asp.NET ViewSwitcher

时间:2014-09-26 18:57:47

标签: asp.net twitter-bootstrap visual-studio-2013 friendly-url

关于Friendly URL和ViewSwitcher的信息似乎很少。

创建文件Default.Mobile.aspx并为其分配主页Site.Mobile.Master然后运行它后,始终返回404'未找到'错误。

任何可能出错的想法,和/或是否有任何好的参考资料?我能找到的唯一东西是2012年或更早。

IIS是v7.0(但VS 2013正在模拟IIS 8.0)。项目是包含MVC的Web表单。正在使用Bootstrap

谢谢

===========================编辑=================== =======================

我现在尝试创建三个单独的项目'开箱即用'

网络| ASP.Net Web应用程序表单和添加MVC和/或API或只是简单的表单

添加Default.Mobile.aspx文件并将其分配给Site.Mobile.Master - 每次运行时都会出现相同的404错误

然后我创建了一个Web Forms项目 - Web | Visual Studio 2012 | ASP.NET Web窗体应用程序。有了这个,Default.Mobile.aspx表格将运行并将切换到主默认文件,但不会再切换回来。

在所有风格上,View Switcher控件只显示为'view |切换到'并且似乎没有加载ViewSwitcher.ascx并显示'x view |切换到y视图'

=====================编辑2014年10月1日====================== ===

解决了ViewSwitcher.ascx的问题。 ViewSwithcher.ascx.vb中的Page_Load事件未连线 - 将“Handles MyBase.Load”添加到最后,现在显示正确的文字,但仍无法显示移动视图 - 叹息

2 个答案:

答案 0 :(得分:2)

这是完整的 Page_Load 代码,可以在桌面和移动页面之间切换。它包括处理MyBase.Load .__ FriendlyUrls_SwitchViews = True 额外参数

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ' Determine current view
    Dim isMobile = WebFormsFriendlyUrlResolver.IsMobileView(New HttpContextWrapper(Context))
    CurrentView = If(isMobile, "Mobile", "Desktop")

    ' Determine alternate view
    AlternateView = If(isMobile, "Desktop", "Mobile")

    Dim strSwitchViewRouteName As String = "AspNet.FriendlyUrls.SwitchView"
    Dim SwitchViewRoute = RouteTable.Routes(strSwitchViewRouteName)
    If SwitchViewRoute Is Nothing Then
        ' Friendly URLs is not enabled or the name of the switch view route is out of sync
        Me.Visible = False
        Return
    End If
    ' Create switch URL from the route, e.g. ~/__FriendlyUrls_SwitchView/Mobile?ReturnUrl=/Page
    Dim url = GetRouteUrl(strSwitchViewRouteName, New With { _
        Key .view = AlternateView, .__FriendlyUrls_SwitchViews = True _
    })
    url += "?ReturnUrl=" & HttpUtility.UrlEncode(Request.RawUrl)
    SwitchUrl = url
End Sub

答案 1 :(得分:0)

通过将此错误添加到web.config

解决了404错误的问题
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
  <add name="ScriptCompressionModule" type="Westwind.Web.ScriptCompressionModule,Westwind.Web" />
</modules>

现在唯一剩下的就是_ViewSwitcher.vbhtml没有解雇 - 越来越近了: - )