1

似乎很少有關於Friendly URL和ViewSwitcher的信息。asp.NET ViewSwitcher

創建文件Default.Mobile.aspx並將其分配給母版頁Site.Mobile.Master,然後運行它404'找不到'錯誤總是返回。

任何想法可能會出錯,和/或是否有任何好的參考資料呢?我能找到的唯一東西是從2012年或更早。

IIS是v7.0(但VS 2013正在模擬IIS 8.0)。項目是包含MVC的Web表單。引導正在使用

謝謝

===========================編輯======== ==================================

我現在已經嘗試創建三個單獨的項目「盒'

網頁| 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視圖'

=====================編輯01 2014年10月================ =========

解決了ViewSwitcher.ascx的問題。 ViewSwithcher.ascx.vb中的Page_Load事件沒有連線 - 添加了「處理MyBase.Load」到最後,現在顯示正確的文本,但仍然無法顯示移動視圖 - 嘆息

+0

你也有一個'Default.aspx'和'Site.Master'文件? – mason 2014-09-26 18:59:16

+0

是的,我當然可以 – gchq 2014-09-26 19:04:30

+0

從http://www.josephguadagno.net/post/2013/05/20/ASPNET-FriendlyUrls-ViewSwitcher-and-jQuery-Mobile獲取了基本信息 – gchq 2014-09-26 19:04:47

回答

2

這是完成Page_Load允許在桌面和移動頁面之間切換的代碼。它包括把手MyBase.Load.__ FriendlyUrls_SwitchViews =真額外的參數

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 
+0

輝煌 - 謝謝! – gchq 2015-02-16 15:32:20

0

加入這個解決404錯誤的問題的web.config

<system.webServer> 
<modules runAllManagedModulesForAllRequests="true"> 
    <add name="ScriptCompressionModule" type="Westwind.Web.ScriptCompressionModule,Westwind.Web" /> 
</modules> 

唯一剩下現在_ViewSwitcher.vbhtml不點火 - 越來越近:-)