【发布时间】:2016-01-14 00:24:51
【问题描述】:
我在使用这个的不同时间都有不良行为:
FormsAuthentication.SetAuthCookie(user.UserName, true);
.Net 将如何/将如何设置 cookie?
我试过这个:(System.Web.HttpContext.Current.User.Identity.IsAuthenticated fails sometimes)
但我的 User.Identity.IsAuthenticated 总是假的
什么给了?
【问题讨论】:
-
SetAuthCookie 不起作用的原因是您没有在 Web 配置中启用表单身份验证。在 system.web 标签内的 web 配置中包含以下设置:
<authentication mode= "Forms" /> -
我一直都有,而且大部分时间都有效
-
请记住,您也可以通过简单地调用
FormsAuthentication.RedirectFromLoginPage方法来设置cookie,该方法将设置身份验证票证/cookie,并将使用重定向到请求的URL或默认URL。 -
是的,我做到了。这样就不手动设置cookie,然后自己设置了?
-
是的,该方法封装了cookie创建功能。
标签: c# asp.net webforms forms-authentication membership-provider