【发布时间】:2016-04-19 04:00:40
【问题描述】:
我正在使用会员服务提供商,但如何获取我的用户名和密码来登录/登录?当我查看此代码时:
if (User.Identity.IsAuthenticated)
// this code always returns false
我之前在用户使用asp:Login登录的时候有这个:
if (Membership.ValidateUser(email, password))
{
// this is true but what am I missing here to make above not be false?
所谓的重复问题/答案使用 SetAuthCookie,据此 (System.Web.HttpContext.Current.User.Identity.IsAuthenticated fails sometimes) 会导致问题,我需要避免它。
【问题讨论】:
-
查看我上面的重复更新。我不能使用 setauthcookie
-
使用我提供的答案,因为它不使用 SetAuthCookie。
-
您需要确保在我的回答中提到的 Web 配置中启用了表单身份验证。不这样做是您所看到的最常见的原因。
标签: c# asp.net webforms asp.net-membership forms-authentication