-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewSwitcher.ascx.vb
35 lines (31 loc) · 1.36 KB
/
ViewSwitcher.ascx.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Imports System.Web
Imports System.Web.Routing
Imports Microsoft.AspNet.FriendlyUrls
Imports Microsoft.AspNet.FriendlyUrls.Resolvers
Public Partial Class ViewSwitcher
Inherits System.Web.UI.UserControl
Protected Property CurrentView As String
Protected Property AlternateView As String
Protected Property SwitchUrl As String
Protected Sub Page_Load(sender As Object, e As EventArgs)
' Determine current view
Dim isMobile = WebFormsFriendlyUrlResolver.IsMobileView(New HttpContextWrapper(Context))
CurrentView = If(isMobile, "Mobile", "Desktop")
' Determine alternate view
AlternateView = If(isMobile, "Desktop", "Mobile")
' Create switch URL from the route, e.g. ~/__FriendlyUrls_SwitchView/Mobile?ReturnUrl=/Page
Dim switchViewRouteName = "AspNet.FriendlyUrls.SwitchView"
Dim switchViewRoute = RouteTable.Routes(switchViewRouteName)
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
Dim url = GetRouteUrl(switchViewRouteName, New With {
.view = AlternateView,
.__FriendlyUrls_SwitchViews = True
})
url += "?ReturnUrl=" & HttpUtility.UrlEncode(Request.RawUrl)
SwitchUrl = url
End Sub
End Class