Advertisement
Guest User

Untitled

a guest
Mar 25th, 2013
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. Login?returnUrl=targetThatNeedsAuthentication
  2.  
  3. AuthorizeAttribute
  4.  
  5. protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
  6. {
  7. ...
  8. var url = // get url of resource that requires authentication
  9. filterContext.Result = new NewResult(url, false);
  10. }
  11.  
  12. /membersonly/Login?redirectUrl=http://localhos:1234/targetThatNeedsAuthentication/
  13.  
  14. public NewResult(string url, bool preserveForm) : base(url)
  15.  
  16. protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
  17. {
  18. filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary
  19. {
  20. { "action", "LogIn" },
  21. { "controller", "Account" },
  22. { "returnUrl", filterContext.HttpContext.Request.RawUrl}
  23. });
  24. }
  25.  
  26. public ActionResult LogIn(LogInModel modelData, string returnUrl = "")
  27. {
  28. // check authorization
  29. ...
  30.  
  31. if (user != null) // user is authorized
  32. {
  33. if (Url.IsLocalUrl(returnUrl))
  34. return Redirect(returnUrl);
  35. else
  36. // return to default authorized page
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement