我Form Authentication
在测试中使用。并且也有一些测试用户名。但是对于指定的名称却发现了一个奇怪的问题。这就是所有测试名称,只有一个命名名称amybeyond
可以在测试中使用。
请帮助检查我的测试代码。
LoginTest.aspx(这是用于输入用户名和密码的登录表单。)
public partial class LoginTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//after succeed validating user. then redirect to LoginSuccess.aspx page.
bool bValidate=Membership.ValidateUser("amybeyond", "11111111");
if (bValidate)
{
FormsAuthentication.SetAuthCookie("AmyBeyond", false);
Response.Redirect("LoginSuccess.aspx");
}
}
}
LoginSuccess.aspx(在此页面中,只需简单地测试重定向后是否对当前请求进行了身份验证。)
public partial class LoginSuccess : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//the HttpContext.Current.Request.IsAuthenticated always false in the IE.
if (HttpContext.Current.Request.IsAuthenticated)
{
Response.Write("ok, you login successfully.");
}
}
}
我确定Membership.ValidateUser
已成功执行和return true
。问题是成功重定向后无法知道身份验证状态。
我不知道我错过了什么还是做错了什么。如果有 。请帮忙告诉我。谢谢。
添加
我阅读了的源代码FormsAuthentication.SetAuthCookie
。并在cookieless="UseCookies"
中添加Forms
元素Web.config
。希望确保将cookie添加到中Response
(通过源代码完成HttpContext.Current.Response.Cookies.Add(cookie)
)。仍然不起作用。
public static void SetAuthCookie(string userName, bool createPersistentCookie, string strCookiePath)
{
Initialize();
HttpContext current = HttpContext.Current;
if (!current.Request.IsSecureConnection && RequireSSL)
{
throw new HttpException(SR.GetString("Connection_not_secure_creating_secure_cookie"));
}
bool flag = CookielessHelperClass.UseCookieless(current, false, CookieMode);
HttpCookie cookie = GetAuthCookie(userName, createPersistentCookie, flag ? "/" : strCookiePath, !flag);
if (!flag)
{
HttpContext.Current.Response.Cookies.Add(cookie);
current.CookielessHelper.SetCookieValue('F', null);
}
else
{
current.CookielessHelper.SetCookieValue('F', cookie.Value);
}
}
添加
http捕获详细信息如下所示。在重定向到此Cookie丢失后,LoginTest.aspx
有一个名为的cookie。请帮忙复习一下。FwLoginCookie
LoginSuccess.aspx
终于明白了为什么发生这种奇怪的事情!这是因为还有另一个名为ACA_USER_READ_ANNOUNCEMENT
发送给响应的cookie 。它太大(超过5800bytes),以至于浏览器(在我的测试中是IE)会忽略所有cookie,其中包括Form身份验证cookie(大约300bytes)。但是,遇到这种情况(巨大的cookie大小)时,其他浏览器(例如chrome / firefox)与IE的行为就不一样。
如果不对。请纠正我。谢谢。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句