点击这里给我发消息
点击这里给我发消息
¥1891.00元
智超淘宝店
Asp.net禁用site.Mobile.Master
转载
文章标签 ASP.Net

RT,在asp.net新的项目中遇到的一个问题。项目使用了Boostrap后网页打开是正常的,但是换成移动端打开这个网页的时候就奇怪了。很多样式不见了。原来是自动切换到了site.Mobile.Master母版。不废话了。看看怎么禁用这个移动端母版吧。

首先在项目下新建一个类如下所示。需要引用using Microsoft.AspNet.FriendlyUrls.Resolvers。

public class MyWebFormsFriendlyUrlResolver : WebFormsFriendlyUrlResolver
    {
        protected override bool TrySetMobileMasterPage(HttpContextBase httpContext, Page page, String mobileSuffix)
        {
            if (mobileSuffix == "Mobile")
            {
                return false;
            }
            else
            {
                return base.TrySetMobileMasterPage(httpContext, page, mobileSuffix);
            }
        }
    }

然后打开App_Start下的RouteConfig,代码修改为如下

public static void RegisterRoutes(RouteCollection routes)
        {
            var settings = new FriendlyUrlSettings();
            settings.AutoRedirectMode = RedirectMode.Permanent;
            routes.EnableFriendlyUrls(settings, new MyWebFormsFriendlyUrlResolver());
        }
重启项目。

转载自:https://www.cnblogs.com/mosdong/p/10886623.html

母版页Site.master中,如果没有<%@ Register Src="~/ViewSwitcher.ascx" TagPrefix="friendlyUrls" TagName="ViewSwitcher" %>,则不会跳转到 MyWebFormsFriendlyUrlResolver类的TrySetMobileMasterPage方法中.