SetAuthCookie Setting Cookie, but not IsAuthentica

2019-08-10 12:26发布

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);

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);

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.

1条回答
姐就是有狂的资本
2楼-- · 2019-08-10 12:59

Solved

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" />
查看更多
登录 后发表回答