FormsAuthentication.RedirectFromLoginPage与Response.Redirect

Sub*_*ike 5 asp.net authentication redirect

这是参考登录后登录用户的问题,这里是FormsAuthentication.RedirectFromLoginPage重新加载页面.

虽然我已经回答了第一个问题,但我承认它只是"共同编程".如果你看到,上述两个问题的答案相互矛盾,但仍然适用于各自的用户.

我想知道这之间究竟有什么区别

FormsAuthentication.SetAuthCookie(USER_NAME, true);

Response.Redirect("copyPastPage.aspx"); 
Run Code Online (Sandbox Code Playgroud)

还有这个 FormsAuthentication.RedirectFromLoginPage(mainSignUp.UserName, true);

在使用方面,我们可以看到Response.Redirect可以允许重定向到任何URL的逻辑差异,因为RedirectFromLoginPage只会重定向到referrer.但那是用法差异.

他们的执行方式是否存在根本分歧?如果没有,任何想法为什么一个人有时会工作,为什么有时呢?在他们每个人的引擎盖下究竟发生了什么?

我有点谷歌,但无法得到任何具体的答案.

Ali*_*tad 11

如果你看一下RedirectFromLoginPage它中的代码基本上是一样的

  • SetAuthCookie
  • 从查询字符串中获取返回URL
  • 清除返回网址

这是一个片段:

    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);
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

但它也检查了对cookie的支持.