禁用aspnet.friendlyurl的平板电脑移动重定向

Jer*_*oen 17 asp.net mobile tablet

我的网站响应Twitter Bootstrap,桌面页面专为平板电脑和桌面设计.aspnet.friendlyUrls将平板电脑设备视为移动设备,并将其发送到".Mobile.aspx"等效设备.如何禁用此行为并将平板电脑保留在桌面页面上?

2个星期后,仍然没有awnser甚至评论?我是唯一一个真正使用aspnet.FriendlyUrls的人,即使它默认分发在新的VS2013 Asp.Net项目中吗?

Tho*_*hom 34

没有设置可以关闭此功能,但您可以通过删除Site.Mobile.Master和ViewSwitcher文件来禁用此功能

不再需要以下文件:

Site.Mobile.Master
- Site.Mobile.Master.cs
- Site.Mobile.Master.designer.cs

ViewSwitcher
- ViewSwitcher.cs
- ViewSwitcher.ascx.cs

感谢@fortboise简化我的回答

  • 不应该在Site.Mobile.Master而不是Site.Master.cs中找到<%@ Register Src ="〜/ ViewSwitcher.ascx"TagPrefix ="friendlyUrls"TagName ="ViewSwitcher"%>这一行吗? (3认同)
  • @ChunLin也是我发现它的地方.我进去并相应地更新了答案. (2认同)
  • 这个解决方案不适用于我的情况(使用visual studio community 2015),当评论和替换提到的行时,解决方案一直在为移动设备加载Site.Mobile.Master ......任何建议或遗忘的步骤? (2认同)

小智 7

去掉也解决不了问题,方法是覆盖TrySetMobileMasterPage。

第一步:创建一个类

public class MyWebFormsFriendlyUrlResolver : Microsoft.AspNet.FriendlyUrls.Resolvers.WebFormsFriendlyUrlResolver
{
protected override bool TrySetMobileMasterPage(HttpContextBase httpContext, Page page, String mobileSuffix)
{
    if (mobileSuffix == "Mobile")
    {
        return false;
    }
    else
    {
        return base.TrySetMobileMasterPage(httpContext, page, mobileSuffix);
    }
}
Run Code Online (Sandbox Code Playgroud)

}

进入 App_Start/RouteConfig 并设置后:

public static void RegisterRoutes(RouteCollection routes)
    {
        var settings = new FriendlyUrlSettings();
        settings.AutoRedirectMode = RedirectMode.Permanent;
        routes.EnableFriendlyUrls(settings, new MyWebFormsFriendlyUrlResolver());
    } 
Run Code Online (Sandbox Code Playgroud)