Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using the following method of detecting a device and displaying a specific view based on it within my Global.asax.cs file


C#
    protected void InitializeBundles()
    {
        var PhoneScripts = new ScriptBundle("~/bundles/MobileJS")
        .Include("~/Scripts/jquery.mobile-1.*",
                "~/Scripts/jquery-1.*");
 
        var PhoneStyles = new StyleBundle("~/bundles/MobileCSS")
        .Include("~/Content/jquery.mobile-1.4.5.min.css",
                "~/Content/jquery.mobile.structure-1.4.5.min.css",
                "~/Content/jquery.mobile.theme-1.4.5.min.css");
 
        BundleTable.Bundles.IgnoreList.Clear();
        BundleTable.Bundles.Add(PhoneScripts);
        BundleTable.Bundles.Add(PhoneStyles);
    }
 
 
    protected void InitializeDisplayModeProviders()
    {
        var phone = new DefaultDisplayMode("Phone")
        {
            ContextCondition = ctx => ctx.GetOverriddenUserAgent() != null && ctx.GetOverriddenUserAgent().Contains("Android")
        };
 
        var phone2 = new DefaultDisplayMode("Phone")
        {
            ContextCondition = ctx => ctx.GetOverriddenUserAgent() != null && ctx.GetOverriddenUserAgent().Contains("iPhone")
        };
 
        var Tablet = new DefaultDisplayMode("Phone")
        {
            ContextCondition = ctx => ctx.GetOverriddenUserAgent() != null && ctx.GetOverriddenUserAgent().Contains("iPad")
        };
 
 
        DisplayModeProvider.Instance.Modes.Insert(0, phone);
        DisplayModeProvider.Instance.Modes.Insert(1, phone2);
        DisplayModeProvider.Instance.Modes.Insert(2, Tablet);
    }
}


This inserts a string that points to a mobile specific view.

It works perfectly, except when I use the Forms Authentication method in the Account controller for my solution.

C#
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
    if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
    {
        return RedirectToLocal(returnUrl);
    }
 
    // If we got this far, something failed, redisplay form
    ModelState.AddModelError("", "The user name or password provided is incorrect.");
    return View(model);
}



This function disregards the Mobile Specific view and automatically directs me to the View that is specific for desktop browsers. in the "RedirectToLocal(returnUrl);" command.

Instead of returning me to /Home/Index.Phone.cshtml

It returns me to /Home/Index.cshtml

It appears that the device detection functionality used in the Global.asax.cs file doesn't support the Redirect from the controller.

Any Ideas how to get this to work.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900