开发者

How to change the name of "ReturnUrl" query string key in ASP.NET's forms authentication?

开发者 https://www.devze.com 2023-04-08 19:01 出处:网络
When you use ASP.NET\'s Form Authentication, a query string key would be passed to login开发者_Python百科 page, which is named \"ReturnUrl\".

When you use ASP.NET's Form Authentication, a query string key would be passed to login开发者_Python百科 page, which is named "ReturnUrl".

For example, if you're not logged in already and you want to see a secure page like http://www.example.com/securepage.aspx, you would be redirected to:

http://www.example.com/login.aspx?ReturnUrl=securepage.aspx

(Or something like that, I'm not pretty sure about ReturnUrl value).

Now, Is there a way to change this ReturnUrl name, to something like path for example? Do we have a kind of configuration in web.config for that?


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

<add key="aspnet:FormsAuthReturnUrlVar" value="path" />


Probably in the easy way you can't do this, because it's hardcoded constant inside of System.Web assembly:

internal static string GetReturnUrl(bool useDefaultIfAbsent)
{
  FormsAuthentication.Initialize();
  HttpContext current = HttpContext.Current;
  string str = current.Request.QueryString["ReturnUrl"];
  // ....
}

But probably you can use some Url rewriting.

Also, check this post on SO: rewrite url. asp.net c#


The FormsAuthentication class is sealed which means you cannot inherit and override from it. Also, it is hard coded to read the request["RETURNURL"] query string parameter.

Why would you want to?


I just want to provide reason why we need to change this parameter name (web form scenario):

I also need to change the "ReturnUrl" for mocking up authentication when creating plugin for umbraco.

umbraco is using membership api and their login.aspx is using "redir" instead of "ReturnUrl", in order to make my solution as small as possible and as independent as possible from umbraco, I need to mock up the workflow for authentication.

Since I cannot change this parameter name, well.... I'll have to readjust.


Of course you can change it. Just add a Global.asax to your project and change the Response.RedirectLocation property during the Application_EndRequest event.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号