Rename the ReturnUrl literal to asp.net mvc

I set the authentication attribute, which sets:

filterContext.Result = new HttpUnauthorizedResult();

so when i try to access

http://www.mysite.com/Forum/Polls 

and I am not authenticated. I am redirected to:

http://www.mysite.com/Account/Log?ReturnUrl=%2FForum%2FPolls

Instead, I want to have the following line:

http://www.mysite.com/Account/Log?back=%2FForum%2FPolls

therefore, instead of "ReturnUrl" you need to "return". Where can I oversee this behavior. Thanks.

+3
source share
2 answers

You can rewrite "ReturnURL" to the EndRequest event.

This is sample code.

protected void Application_EndRequest()
{
  if (Response.StatusCode != 301 && Response.StatusCode != 302) return;

  var targetUrl = Response.RedirectLocation.Replace("ReturnUrl","back");
  Response.RedirectLocation = targetUrl;
}

Hope this code.

+2
source

, . System.Web.Security.FormsAuthentication.GetLoginPage() , , . , System.Web 2.0.0.0

0

Source: https://habr.com/ru/post/1723481/


All Articles