Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When you use ASP.NET's Form Authentication, a query string key would be passed to login 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?

like image 651
Saeed Neamati Avatar asked Dec 22 '22 08:12

Saeed Neamati


2 Answers

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

<add key="aspnet:FormsAuthReturnUrlVar" value="path" />
like image 91
Fabian Vilers Avatar answered Dec 23 '22 21:12

Fabian Vilers


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#

like image 22
Samich Avatar answered Dec 23 '22 20:12

Samich