Tip – Disable mobile master page in asp.net
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: mastepage, mobile masterpage, site.mobile.master В· Posted in: C#, Tips and Tricks
5 Responses
isMobileDevice=false
use this in system.web in web config.
Hi Pankaj,
It is good idea
Below option will override during service pack updates though.
Instead below one can be used which will not override during service pack updates
Regards,
Adi
Adi’s solution in the above response worked for me!
Thanks for this article!
Thanks for solution
Thank you for your solution. This worked perfectly for my site.
Leave a Reply