Mobile Redirection to ASP.NET Webforms & MVC application


Working pretty cool staffs with ASP.NET MVC, loved the Wrox books of ASP.NET MVC 2.0 of ScottGu & learning ASP.NET MVC 3.0 in parallel (Razor syntaxes & JQuery for mobile). ASP.Net MVC provides options to redirect the desktop web application to mobile view.

1. Using the same controller & View of desktop web application to render it to mobile.

2. Using the same controller but rendering different views according to the  specification of the device (“~/Mobile/Home/I-Phone/Index.aspx”  OR “~/Mobile/Home/Windows Mobile/Index.aspx”) including seperate master pages for differnet mobile view.

3. Using different Controller & different Views for the same application by adding seperate “Mobile” area in existing MVC web application.

  • Similarly the redirection logic works well for Webforms as well as the adding mobile redirection logic in Session_Start method of Global.asax.cs.
  • void Session_Start(object sender, EventArgs e)
            {
                // Code that runs when a new session is started
                
                // Redirect Mobile users to the mobile home page
    
                HttpRequest httpRequest = HttpContext.Current.Request;
                if (httpRequest.Browser.IsMobileDevice)
                {
                    string path = httpRequest.Url.PathAndQuery;
                    bool isOnMobile = path.StartsWith("/Mobile/",
                                                 StringComparison.OrdinalIgnoreCase);
                    if (!isOnMobile)
                    {
                        string redirectTo = "~/Mobile/";
    
                        // Could also add special logic to redirect from certain
                        // recognized pages to the mobile equivalents of those
                        // pages(where they exist). For example,
                        //if(HttpContext.Current.Handler is UserRegistration)
                        //redirectTo ="~/Mobile/Register.aspx"
    
                        HttpContext.Current.Response.Redirect(redirectTo);
                    }
                }
    
    
            }
    More information in our asp.net mvc forum .
    http://www.asp.net/learn/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application

 

 

Advertisements

About Anindita
Anindita Basak is working as Big Data Cloud Consultant in Microsoft. Worked in multiple MNCs as Developer & Senior Developer on Microsoft Azure, Data Platform, IoT & BI , Data Visualization, Data warehousing & ETL & of course in Hadoop platform.She played both as FTE & v- employee in Azure platform teams of Microsoft.Passionate about .NET , Java, Python & Data Science. She is also an active Big Data & Cloud Trainer & would love share her experience in IT Training Industry. She is an author, forum contributor, blogger & technical reviewer of various books on Big Data Hadoop, HDInsight, IoT & Data Science, SQL Server PDW & PowerBI.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: