SetAuthCookie设置的Cookie,但不IsAuthenticated在后续请求 [英] SetAuthCookie Setting Cookie, but not IsAuthenticated on Subsequent Requests

查看:737
本文介绍了SetAuthCookie设置的Cookie,但不IsAuthenticated在后续请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code其中我们创建了一个身份验证票证。创建票后,我们调用SetAuthCookie设置cookie,如:

I have some code where we create an authentication ticket. After creating the ticket, we call SetAuthCookie to set the cookie such as:

FormsAuthentication.SetAuthCookie(username, true);
Response.Redirect("/", true);

如果我检查根页上看到,如果用户进行身份验证,则返回false。不过,如果我硬code中的用户名和做的:

If I check on the root page to see if the user is authenticated, it returns false. However, if I hard code the username in and do:

FormsAuthentication.GetAuthCookie("jason", true).value);

我得到相应的cookie值。因此,该cookie的存在。但名称和标志不会被修改。任何想法,以什么我的问题可能呢?我使用ASP.NET 4和MVC。

I get the appropriate cookie value. So, the cookie exists. But the name and the flag are not modified. Any ideas as to what my issue could be? I'm using ASP.NET 4 and MVC.

推荐答案

解决

我是缺少在web.config中的表格一节。它为本地测试除去登录表单驻留在另一台服务器上。因此,加入以下的web.config解决了我的问题:

I was missing the forms section in the web.config. It was removed for local testing as the login form resides on another server. So, adding the following to web.config solved my issue:

<authentication mode="Forms" />

这篇关于SetAuthCookie设置的Cookie,但不IsAuthenticated在后续请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆