ASP.NET关闭FriendlyURLs mobile.master页面

时间:2013-12-19 09:34:02

标签: asp.net friendly-url

我想完全关闭Site.Mobile.Master页面。我的网站响应迅速,我希望移动浏览器使用相同的母版页。

如何在ASP.NET友好URL中执行此操作

由于

8 个答案:

答案 0 :(得分:13)

删除Site.Mobile.Master页面,而友情网址只会使用常规的Site.Master页面。

答案 1 :(得分:11)

当前版本的Web窗体友好URL(1.0.2)中似乎存在一个错误,该错误使得尝试访问友好URL代码中site.mobile.master的{​​{1}}中断。我被这个烧了。

为了解决这个问题,我在http://www.davidwilhelmsson.com/disabling-mobile-master-pages-with-asp-net-friendly-urls/使用了代码的修改版本 - 首先制作了一个解析器类:

"The relative virtual path 'Site.Mobile.Master' is not allowed here."

然后在我的/// <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); } } 课程中使用它:

RouteConfig

答案 2 :(得分:7)

没有简单的方法可以摆脱移动母版页,这简直太奇怪了。如果我删除Site.Mobile.Master.master,我结束时出现错误&#34;文件&#39; /Site.Mobile.Master'不存在&#34;。

我为解决这个问题所做的是将以下代码添加到Site.Mobile.Master.cs Page_Load事件中。

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);

答案 3 :(得分:2)

当我删除Site.Mobil.Master时,页面被破坏了。 所以... 我更喜欢在Site.Mobile.Master中设置Site.Master的信息

CodeBehind =“Site.Master.cs”Inherits =“App.SiteMaster”

它不是最好的选择(LOL),但解决了!

答案 4 :(得分:1)

我设法通过更改以下内容来解决此问题:

1)我删除了mobile.master

2)我将ViewSwitcher.ascx.cs的代码更改为

protected void Page_Load(object sender, EventArgs e)
    {
        CurrentView = "Desktop";
        AlternateView = "Desktop";

        // Create switch URL from the route, e.g. ~/__FriendlyUrls_SwitchView/Mobile?ReturnUrl=/Page
        var switchViewRouteName = "AspNet.FriendlyUrls.SwitchView";
        var switchViewRoute = RouteTable.Routes[switchViewRouteName];
        if (switchViewRoute == null)
        {
            // Friendly URLs is not enabled or the name of the switch view route is out of sync
            this.Visible = false;
            return;
        }
        var url = GetRouteUrl(switchViewRouteName, new { view = AlternateView, __FriendlyUrls_SwitchViews = true });
        url += "?ReturnUrl=" + HttpUtility.UrlEncode(Request.RawUrl);
        SwitchUrl = url;

    }

3)这不起作用,直到我删除整个目录并重新发布它。我认为,删除一些特定文件也可能有所帮助。但由于我没有这种环境,所以我更容易。

答案 5 :(得分:0)

答案 6 :(得分:0)

我解决了它只是在“ViewSwitcher.ascx”的“Page_Load”事件结束时添加了默认保存的重定向:     Response.Redirect的(URL) 因此子结果如下:

  

受保护的子Page_Load(发件人为对象,e为EventArgs)           '确定la vista实际           Dim isMobile = WebFormsFriendlyUrlResolver.IsMobileView(New HttpContextWrapper(Context))           CurrentView = If(isMobile,“Mobile”,“Desktop”)

    ' Determinar la vista alternativa
    AlternateView = If(isMobile, "Desktop", "Mobile")

    ' Create URL de conmutador a partir de la ruta, p. ej. ~/__FriendlyUrls_SwitchView/Mobile?ReturnUrl=/Page
    Dim switchViewRouteName = "AspNet.FriendlyUrls.SwitchView"
    Dim switchViewRoute = RouteTable.Routes(switchViewRouteName)
    If switchViewRoute Is Nothing Then
        ' Las URL descriptivas no están habilitadas o el nombre de la ruta de la vista del conmutador no está sincronizado
        Me.Visible = False
        Return
    End If
    Dim url = GetRouteUrl(switchViewRouteName, New With {
        .view = AlternateView,
        .__FriendlyUrls_SwitchViews = True
    })
    url += "?ReturnUrl=" & HttpUtility.UrlEncode(Request.RawUrl)
    SwitchUrl = url
    **Response.Redirect(url)**
End Sub

答案 7 :(得分:0)

我发现删除(或重命名)Site.Mobile.Master和ViewSwitcher.ascx更容易。这似乎对我来说很好。