2012-02-23 116 views
0

我想比较httpcontext.current.user.identity.name的值与存储在我的sql数据库表中的值。它在我的本地机器上正常工作。但是httpcontext.current.user.identity.name在托管在服务器上的同一网站时返回空白。在IIS中“允许匿名访问”已启用,我不想禁用它。网上有很多解决方案,但我无法找到一旦适合我的要求。httpcontext。 current.user.identity.name为空

回答

0

您是否尝试过设置AuthCookie?现在

if (Membership.ValidateUser(txtBxusername, txtBxpassword)) 
{ 
    FormsAuthentication.SetAuthCookie(strUsername, true); 
    bool isAuth = User.Identity.IsAuthenticated; 
    FormsAuthentication.RedirectFromLoginPage(userName, chkBxRememberMe.Checked); 
} 

,你应该能够使用下面的代码中的其他地方:

string userName = User.Identity.Name; 
+0

我想这将在窗体身份验证的情况下工作。我的是windows认证。 – user598082 2012-02-23 06:55:40

+0

你在你的标签中为这个问题指定了asp.net,并且你提到了IIS。 Windows身份验证在您的系统中进入它的位置?多年来,我在几个项目中使用了asp成员资格,并且可以验证User.Identity.Name将在ASP.net中工作。你能提供关于你的设置的更多细节吗? – Seany84 2012-02-23 07:03:00

+0

对不起,我正在使用Asp.net和web.config文件我已经设置。 – user598082 2012-02-23 07:16:01