-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewSwitcher.ascx.cs
More file actions
32 lines (26 loc) · 1.08 KB
/
ViewSwitcher.ascx.cs
File metadata and controls
32 lines (26 loc) · 1.08 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.FriendlyUrls;
using Microsoft.AspNet.FriendlyUrls.Resolvers;
public partial class ViewSwitcher : System.Web.UI.UserControl
{
protected string CurrentView { get; private set; }
protected string AlternateView { get; private set; }
protected string SwitchUrl { get; private set; }
protected void Page_Load(object sender, EventArgs e)
{
// Determine current view
var isMobile = WebFormsFriendlyUrlResolver.IsMobileView(new HttpContextWrapper(Context));
CurrentView = isMobile ? "Mobile" : "Desktop";
// Determine alternate view
AlternateView = isMobile ? "Desktop" : "Mobile";
// Create switch URL from the route, e.g. ~/__FriendlyUrls_SwitchView/Mobile?ReturnUrl=/Page
var url = GetRouteUrl("AspNet.FriendlyUrls.SwitchView", new { view = AlternateView });
url += "?ReturnUrl=" + HttpUtility.UrlEncode(Request.RawUrl);
SwitchUrl = url;
}
}