I would like to turn the Site.Mobile.Master page off completely. My site is responsive and i want mobile browsers to use the same master page.
How can i do this in ASP.NET friendly URLs
Thanks
Delete the Site.Mobile.Master page, and Friendly URLs will just use the regular Site.Master page instead.
There actually seems to be a bug in the current version of Web Forms friendly URLs (1.0.2) that makes this attempted access to the site.mobile.master
break with "The relative virtual path 'Site.Mobile.Master' is not allowed here."
in the friendly URL code. I just was burned by this.
To fix it, I used a modified version of the code at http://www.davidwilhelmsson.com/disabling-mobile-master-pages-with-asp-net-friendly-urls/ - first made a resolver class:
/// <summary>
/// This is a hack to force no mobile URL resolution in FriendlyUrls. There's some kind of bug in the current version that
/// causes it to do an internal failed resolve of a mobile master even though there is none.
/// </summary>
public class BugFixFriendlyUrlResolver: Microsoft.AspNet.FriendlyUrls.Resolvers.WebFormsFriendlyUrlResolver {
protected override bool TrySetMobileMasterPage(HttpContextBase httpContext, Page page, string mobileSuffix) {
return false;
//return base.TrySetMobileMasterPage(httpContext, page, mobileSuffix);
}
}
then used it in my RouteConfig
class:
public static void RegisterRoutes(RouteCollection routes) {
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings, new BugFixFriendlyUrlResolver());
}
It is relly weird that there is no easy way to get rid of mobile master page. If I delete Site.Mobile.Master.master, I ended with the error "The file '/Site.Mobile.Master' does not exists".
What I did to solve this issue was I added following codes into Site.Mobile.Master.cs Page_Load event.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With