我怎样才能改变&QUOT的名称; RETURNURL"通过ASP.NET MVC使用的参数? [英] How can I change the name of the "ReturnUrl" parameter used by ASP.NET MVC?
问题描述
RETURNURL
是一种丑陋。我想使用重定向
来代替。我怎么可以指定应该用于窗体身份验证与 [授权]
属性一起重定向的URL参数的名称?还是我必须建立一个个IAuthorizationFilter实现? (
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? :(
例如:
[Authorize]
public class Tools : Controller
{
public ActionResult Index()
{
return View();
}
}
当谁不是在访问 http://example.com/tools 登录用户,我希望他们被重定向到 http://example.com/account/logon?redirect=%2ftools
,而不是默认的 http://example.com/Account / LogOn支持?RETURNURL =%2ftools
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
对于/帐号/登录的一部分,我可以修改我的路线在Global.asax中,改变
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>
在web.config中。但我不知道如何改变RETURNURL参数。
in web.config. But I don't know how to change the ReturnUrl parameter.
推荐答案
不是最好的解决方案,但它的工作原理...
Not the BEST solution around, but it works...
<rule name="FormsAuthentication" stopProcessing="true">
<match url="^account/log(i|o)n$" />
<conditions>
<add input="{QUERY_STRING}" pattern="^ReturnUrl=([^=&]+)$" />
</conditions>
<action type="Redirect" url="account/logon?redirect={C:1}" appendQueryString="false" />
</rule>
这篇关于我怎样才能改变&QUOT的名称; RETURNURL&QUOT;通过ASP.NET MVC使用的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!