You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.5 KiB

4 years ago
  1. using Microsoft.AspNet.FriendlyUrls.Resolvers;
  2. using System;
  3. using System.Web;
  4. using System.Web.Routing;
  5. namespace JMEAgentSystem
  6. {
  7. public partial class ViewSwitcher : System.Web.UI.UserControl
  8. {
  9. protected string CurrentView { get; private set; }
  10. protected string AlternateView { get; private set; }
  11. protected string SwitchUrl { get; private set; }
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. // Determine current view
  15. var isMobile = WebFormsFriendlyUrlResolver.IsMobileView(new HttpContextWrapper(Context));
  16. CurrentView = isMobile ? "Mobile" : "Desktop";
  17. // Determine alternate view
  18. AlternateView = isMobile ? "Desktop" : "Mobile";
  19. // Create switch URL from the route, e.g. ~/__FriendlyUrls_SwitchView/Mobile?ReturnUrl=/Page
  20. var switchViewRouteName = "AspNet.FriendlyUrls.SwitchView";
  21. var switchViewRoute = RouteTable.Routes[switchViewRouteName];
  22. if (switchViewRoute == null)
  23. {
  24. // Friendly URLs is not enabled or the name of the switch view route is out of sync
  25. this.Visible = false;
  26. return;
  27. }
  28. var url = GetRouteUrl(switchViewRouteName, new { view = AlternateView, __FriendlyUrls_SwitchViews = true });
  29. url += "?ReturnUrl=" + HttpUtility.UrlEncode(Request.RawUrl);
  30. SwitchUrl = url;
  31. }
  32. }
  33. }