- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在测试中使用了 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
已成功执行并且返回 true
。问题是它无法在成功重定向后知道身份验证状态。
我不知道我是漏掉了什么还是做错了什么。如果有 。请帮忙告诉我。谢谢。
已添加
我阅读了FormsAuthentication.SetAuthCookie
的源代码。并在 Web.config
的 Forms
元素中添加 cookieless="UseCookies"
。希望确保将 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 捕获细节如下所示。在 LoginTest.aspx
中有一个名为 FwLoginCookie
的 cookie,在重定向到 LoginSuccess.aspx
之后,这个 cookie 丢失了。请帮忙审核。
最佳答案
终于明白为什么会发生这种奇怪的事情了!这是因为有另一个名为 ACA_USER_READ_ANNOUNCEMENT
的 cookie 发送给响应。它太大(超过 5800 字节)以至于浏览器(在我的测试中是 IE)会忽略所有 cookie,包括表单例份验证 cookie(大约 300 字节)。但其他浏览器如 chrome/firefox 在遇到这种情况时与 IE 的行为不同(巨大的 cookie 大小。)。
如果不对。请纠正我。谢谢。
关于c# - 为什么 FormsAuthentication.SetAuthCookie 在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20648229/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!