How to get HandleUnauthorizedRequest to return correct url?

Posted by Jova on Stack Overflow See other posts from Stack Overflow or by Jova
Published on 2010-05-20T07:18:35Z Indexed on 2010/05/20 7:20 UTC
Read the original article Hit count: 1604

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?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about authorize-attribute