Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Login?returnUrl=targetThatNeedsAuthentication
- AuthorizeAttribute
- protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
- {
- ...
- var url = // get url of resource that requires authentication
- filterContext.Result = new NewResult(url, false);
- }
- /membersonly/Login?redirectUrl=http://localhos:1234/targetThatNeedsAuthentication/
- public NewResult(string url, bool preserveForm) : base(url)
- protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
- {
- filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary
- {
- { "action", "LogIn" },
- { "controller", "Account" },
- { "returnUrl", filterContext.HttpContext.Request.RawUrl}
- });
- }
- public ActionResult LogIn(LogInModel modelData, string returnUrl = "")
- {
- // check authorization
- ...
- if (user != null) // user is authorized
- {
- if (Url.IsLocalUrl(returnUrl))
- return Redirect(returnUrl);
- else
- // return to default authorized page
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement