开发者

FormsAuthentication.RedirectFromLoginPage Vs Response.Redirect

开发者 https://www.devze.com 2023-02-24 05:28 出处:网络
This is with reference to a question asked here Login user after signup and here FormsAuthentication.RedirectFromLoginPage reload page.

This is with reference to a question asked here Login user after signup and here FormsAuthentication.RedirectFromLoginPage reload page.

Though I have answered the first question but i will admit that it's just "programming by co-incidence". If you see, answers to above two questions contradict each other but still both worked for respective users.

I would like to know what is the exact difference between this开发者_StackOverflow

FormsAuthentication.SetAuthCookie(USER_NAME, true);

Response.Redirect("copyPastPage.aspx"); 

And this FormsAuthentication.RedirectFromLoginPage(mainSignUp.UserName, true);

In terms of usage, we can see a logical difference that Response.Redirect can allow redirecting to any URL as against RedirectFromLoginPage would redirect only to the referrer. But that's usage difference.

Is there any fundamental diffence in their way of execution? If not, any thoughts why one would work at times and why other at times? what exactly happens under the hood of each of them?

I have google a bit but could not get any concrete answer.


If you look at the code in RedirectFromLoginPage it does essentially the same

  • SetAuthCookie
  • get return URL from query string
  • Clear return URL

Here is a snippet:

    HttpContext current = HttpContext.Current;
    string returnUrl = GetReturnUrl(true);
    if (CookiesSupported || IsPathWithinAppRoot(current, returnUrl))
    {
        SetAuthCookie(userName, createPersistentCookie, strCookiePath);
        returnUrl = RemoveQueryStringVariableFromUrl(returnUrl, FormsCookieName);
        if (!CookiesSupported)
        {
            int index = returnUrl.IndexOf("://", StringComparison.Ordinal);
            if (index > 0)
            {
                index = returnUrl.IndexOf('/', index + 3);
                if (index > 0)
                {
                    returnUrl = returnUrl.Substring(index);
                }
            }
        }

But it does also check for support for cookie.

0

精彩评论

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