ASP.net代码看不到浏览器设置的cookie

时间:2014-04-01 15:25:50

标签: asp.net cookies forms-authentication asp.net-3.5

我在ASP.NET 3.5应用程序中使用Forms身份验证。当我登录时,我可以在Chrome中看到已经设置了auth cookie并将其发送回ASP.NET Development Server。

但是,当它在Global.asax

中到达此代码时
void Application_AuthenticateRequest(object sender, EventArgs e)
{
    string cookieName = FormsAuthentication.FormsCookieName;
    HttpCookie authCookie = Context.Request.Cookies[cookieName];

我的代码设置的auth cookie不再存在!即使Chrome已经为该请求发送了Cookie! Context.Request中只显示ASP.NET会话cookie。

我已尝试更改身份验证Cookie的名称,但这并没有帮助。

顺便说一句,即使我更改了web.config以指定表单auth,它也要求浏览器执行NTLM身份验证。

1 个答案:

答案 0 :(得分:0)

问题是我在事件日志中收到以下错误:

 Forms authentication failed for the request. Reason: The ticket supplied was invalid. 

但我没看过事件日志。

显然,ASP.NET要求将cookie值设置为加密票证,如this code sample所示。尽管一些文档暗示了,但您不能只在表单身份验证cookie中添加任何内容。

相关问题