Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you login Action gets hit, check if they are on a mobile device and then redirect to the mobile login page if they are.</p> <pre><code>private static string[] mobileDevices = new string[] {"iphone","ppc", "windows ce","blackberry", "opera mini","mobile","palm", "portable","opera mobi" }; public static bool IsMobileDevice(string userAgent) { // TODO: null check userAgent = userAgent.ToLower(); return mobileDevices.Any(x =&gt; userAgent.Contains(x)); } </code></pre> <p>Then in your Action:</p> <pre><code>public ActionResult Index() { if (MobileHelper.IsMobileDevice(Request.UserAgent)) { // Send to mobile route. return RedirectToAction("Login", "MobileActivation"); } // Otherwise do normal login } </code></pre> <p><strong>Edit:</strong></p> <p>If you wanted to apply this broadly accross your application you could do the following.</p> <p>Create an ActionFilter that you could apply anywhere something like this:</p> <pre><code>[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public sealed class RedirectToMobileArea : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { var rd = filterContext.HttpContext.Request.RequestContext.RouteData; var currentAction = rd.GetRequiredString("action"); var currentController = rd.GetRequiredString("controller"); string currentArea = rd.Values["area"] as string; if (!currentArea.Equals("mobile", StringComparison.OrdinalIgnoreCase) &amp;&amp; MobileHelper.IsMobileDevice(Request.UserAgent)) { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", currentController }, { "action", currentAction }, { "area", "mobile" } }); } } } </code></pre> <p>This filter will take any action check if its mobile (and not in mobile area already) and send it to same action and controller in the mobile area. <strong><em>NOTE</em></strong> If you go with controllers of same name you will have to register your routes with the controller namespace <a href="https://stackoverflow.com/a/5065454/148998">see this answer</a></p> <p>Then you could either apply the filter to each action like: </p> <pre><code>[RedirectToMobileArea] public ActionResult Index() { // do stuff. } </code></pre> <p>Or if you want to do it EVERYWHERE create a BaseController that all your controllers inherit from and apply it to that:</p> <pre><code>[RedirectToMobileArea] public abstract class BaseController : Controller { } </code></pre> <p>Then inherit from it:</p> <pre><code>public HomeController : BaseController { } </code></pre> <p>I havent tested any of this but it should work...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload