Tip – Disable mobile master page in asp.net

Tip – Disable mobile master page in asp.net
7 votes, 4.43 avg. rating (88% score)

Tip – Disable mobile master page in asp.net

In most of the web applications currently, they are designed with responsive css in mind. So, one master page is enough. Asp.net switches to mobile master page (site.mobile.master) automatically when viewed in mobile. How to disable that?

Removing the mobile master page will not help. If it is removed application will throw error like Site.Mobile.Master does not exist. All you have to do is set the alternate view and redirect in Site.Mobile.Master.cs file. Place the below code in pageload event and the application will be redirected to normal master page.

var AlternateView = "Desktop";
var switchViewRouteName = "AspNet.FriendlyUrls.SwitchView";
var url = GetRouteUrl(switchViewRouteName, new { view = AlternateView, __FriendlyUrls_SwitchViews = true });
url += "?ReturnUrl=" + HttpUtility.UrlEncode(Request.RawUrl);
Response.Redirect(url);

November 10, 2014 В· Adi В· 5 Comments
Tags: , ,  В· Posted in: C#, Tips and Tricks

5 Responses

  1. Pankaj Verma - March 1, 2015

    isMobileDevice=false

    use this in system.web in web config.

  2. Adi - March 1, 2015

    Hi Pankaj,
    It is good idea
    Below option will override during service pack updates though.

    <capability name="isMobileDevice" value="false"/>
    

    Instead below one can be used which will not override during service pack updates

    <browserCaps>
      <result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <filter>isMobileDevice=false</filter>
    </browserCaps>

    Regards,
    Adi

  3. jd - April 17, 2015

    Adi’s solution in the above response worked for me!
    Thanks for this article!

  4. aakash - May 17, 2015

    Thanks for solution

  5. Julianne - July 13, 2016

    Thank you for your solution. This worked perfectly for my site.

Leave a Reply

What is 5 + 11 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)