Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The returnUrl querystring parameter is added to the redirect to the login page inside the FormsAuthentication class in the System.Web.dll assembly. FormsAuthenticion.RedirectToLoginPage method overloads end up calling the internal method, GetLoginPage. Both the name of the "ReturnUrl" variable and the LoginUrl can be overridden via web.config settings.</p> <p>When the default AuthorizeAttribute encounters an unauthorized request, it just returns an HttpUnauthorizedResult, which is just a wrapper around the HttpStatusCodeResult with a status code of 401. The FormsAuthenticationModule kicks in behind the scenes and does the rest of the work. There is no direct interaction between MVC and these base classes, unless of course you are calling the FormsAuthentication class static methods directly.</p> <p><em><strong>Your solution is a standard one, when you want to override this behavior.</em></strong></p> <p>The GetLoginPage method that does the work is as follows:</p> <pre><code>internal static string GetLoginPage(string extraQueryString, bool reuseReturnUrl) { HttpContext current = HttpContext.Current; string loginUrl = FormsAuthentication.LoginUrl; if (loginUrl.IndexOf('?') &gt;= 0) { loginUrl = FormsAuthentication.RemoveQueryStringVariableFromUrl(loginUrl, FormsAuthentication.ReturnUrlVar); } int num = loginUrl.IndexOf('?'); if (num &gt;= 0) { if (num &lt; loginUrl.Length - 1) { loginUrl = string.Concat(loginUrl, "&amp;"); } } else { loginUrl = string.Concat(loginUrl, "?"); } string str = null; if (reuseReturnUrl) { str = HttpUtility.UrlEncode(FormsAuthentication.GetReturnUrl(false), current.Request.QueryStringEncoding); } if (str == null) { str = HttpUtility.UrlEncode(current.Request.RawUrl, current.Request.ContentEncoding); } loginUrl = string.Concat(loginUrl, FormsAuthentication.ReturnUrlVar, "=", str); if (!string.IsNullOrEmpty(extraQueryString)) { loginUrl = string.Concat(loginUrl, "&amp;", extraQueryString); } return loginUrl; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload