daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Jun 24th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class FbAuthorize : ActionFilterAttribute
  2. {
  3.     public override void OnActionExecuting(ActionExecutingContext filterContext)
  4.     {
  5.         if (!Service.SignedIn())
  6.             RouteToAction("Account", "Index"); // Fictional method (I wish it existed)
  7.     }
  8. }
  9.    
  10. public static class ServerHelper {
  11.  
  12.   public static void Transfer(ActionExecutingContext filterContext, string url) {
  13.  
  14.     // Rewrite path
  15.     HttpContext.Current.RewritePath(GetPath(filterContext, url), false);
  16.  
  17.     IHttpHandler httpHandler = new System.Web.Mvc.MvcHttpHandler();
  18.  
  19.     // Process request
  20.     httpHandler.ProcessRequest(HttpContext.Current);
  21.     filterContext.HttpContext.Response.End();
  22.   }
  23.  
  24.   private static string GetPath(ActionExecutingContext filterContext, string url) {
  25.       HttpRequestBase request = filterContext.HttpContext.Request;
  26.  
  27.       UriBuilder uriBuilder = new UriBuilder(request.Url.Scheme, request.Url.Host, request.Url.Port, request.ApplicationPath);
  28.  
  29.       uriBuilder.Path += url;
  30.  
  31.       return filterContext.HttpContext.Server.UrlDecode(uriBuilder.Uri.PathAndQuery);
  32.   }
  33. }
  34.    
  35. ServerHelper.Transfer(filterContext, "Account/Index");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top