How can I change the name of the “ReturnUrl” param

2020-03-02 01:49发布

ReturnUrl is kind of ugly. I'd like to use redirect instead. How can I specify the name of the parameter that should be used for forms authentication redirect URLs in conjunction with the [Authorize] attribute? Or do I have to create an IAuthorizationFilter implementation? :(

Example:

[Authorize]
public class Tools : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

When a user who is not logged in visits http://example.com/tools, I'd like them to be redirected to http://example.com/account/logon?redirect=%2ftools, instead of the default http://example.com/Account/LogOn?ReturnUrl=%2ftools

For the /account/logon part, I can modify my routes in Global.asax and change

<authentication mode="Forms">
  <forms loginUrl="~/account/logon" timeout="2880" />
</authentication>

in web.config. But I don't know how to change the ReturnUrl parameter.

7条回答
女痞
2楼-- · 2020-03-02 02:17

Add this key to the appSettings section of your web.config

<add key="aspnet:FormsAuthReturnUrlVar" value="redirect" />
查看更多
登录 后发表回答