2012-02-23 112 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