这是参考此处Login user after signup和此处FormsAuthentication.RedirectFromLoginPage reload page提出的问题。
虽然我已经回答了第一个问题,但我承认它只是“共同编程”。如果你看到,上述两个问题的答案相互矛盾,但仍然适用于各自的用户。
我想知道这个
之间的确切区别FormsAuthentication.SetAuthCookie(USER_NAME, true);
Response.Redirect("copyPastPage.aspx");
这是FormsAuthentication.RedirectFromLoginPage(mainSignUp.UserName, true);
在使用方面,我们可以看到Response.Redirect可以允许重定向到任何URL的逻辑区别,因为RedirectFromLoginPage只会重定向到引用者。但那是用法差异。
他们的执行方式是否存在根本分歧?如果没有,任何想法为什么一个人有时会工作,为什么有时呢?在他们每个人的引擎盖下究竟发生了什么?
我有点谷歌,但无法得到任何具体的答案。
答案 0 :(得分:11)
如果你看一下RedirectFromLoginPage
中的代码,它基本上是相同的
SetAuthCookie
这是一个片段:
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);
}
}
}
但它也检查了对cookie的支持。