How to get HandleUnauthorizedRequest to return correct url?
- by Jova
I'm writing a custom AuthorizeAttribute which should redirect unauthorized users to the login page.
My HandleUnauthorizedRequest method looks like this,
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) {
RouteValueDictionary returnRoute = new RouteValueDictionary();
returnRoute["controller"] = "Account";
returnRoute["action"] = "Login";
returnRoute["returnUrl"] = filterContext.HttpContext.Request.Url.AbsolutePath;
filterContext.Result = new RedirectToRouteResult(returnRoute);
}
Unfortunately it's not working properly as the returning url looks like this,
www.mydomain.com/?controller=Account&action=Login&returnUrl=%2FUser%2FEditProfile%2FUsername
What is the reason for this and how do I correct it?