markus / ConvertService / ServiceBase / UploadFonts / ViewSwitcher.ascx.cs @ ab7fe8c0
이력 | 보기 | 이력해설 | 다운로드 (1.55 KB)
1 | 950e6b84 | taeseongkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Web; |
||
5 | using System.Web.Routing; |
||
6 | using System.Web.UI; |
||
7 | using System.Web.UI.WebControls; |
||
8 | using Microsoft.AspNet.FriendlyUrls.Resolvers; |
||
9 | |||
10 | namespace UploadFonts |
||
11 | { |
||
12 | public partial class ViewSwitcher : System.Web.UI.UserControl |
||
13 | { |
||
14 | protected string CurrentView { get; private set; } |
||
15 | |||
16 | protected string AlternateView { get; private set; } |
||
17 | |||
18 | protected string SwitchUrl { get; private set; } |
||
19 | |||
20 | protected void Page_Load(object sender, EventArgs e) |
||
21 | { |
||
22 | // Determine current view |
||
23 | var isMobile = WebFormsFriendlyUrlResolver.IsMobileView(new HttpContextWrapper(Context)); |
||
24 | CurrentView = isMobile ? "Mobile" : "Desktop"; |
||
25 | |||
26 | // Determine alternate view |
||
27 | AlternateView = isMobile ? "Desktop" : "Mobile"; |
||
28 | |||
29 | // Create switch URL from the route, e.g. ~/__FriendlyUrls_SwitchView/Mobile?ReturnUrl=/Page |
||
30 | var switchViewRouteName = "AspNet.FriendlyUrls.SwitchView"; |
||
31 | var switchViewRoute = RouteTable.Routes[switchViewRouteName]; |
||
32 | if (switchViewRoute == null) |
||
33 | { |
||
34 | // Friendly URLs is not enabled or the name of the switch view route is out of sync |
||
35 | this.Visible = false; |
||
36 | return; |
||
37 | } |
||
38 | var url = GetRouteUrl(switchViewRouteName, new { view = AlternateView, __FriendlyUrls_SwitchViews = true }); |
||
39 | url += "?ReturnUrl=" + HttpUtility.UrlEncode(Request.RawUrl); |
||
40 | SwitchUrl = url; |
||
41 | } |
||
42 | } |
||
43 | } |