2013-02-11 48 views
0

我一直在寻找这个很长一段时间,发现很多链接,但没有一个工作。无法获取当前用户

当我在webforms中工作时,我能够通过以下代码获取当前用户。

System.Security.Principal.IIdentity identity = HttpContext.Current.User.Identity; 
string user = identity.Name; 

但在MVC项目current不工作,所以我尝试了通过

HttpContext.User.Identity 

当我写identity.name保持它一次又一次空。

我想获取当前登录的Windows用户的用户名。我怎么能得到这个。

+0

你试图从一个控制器action方法中做到这一点?你尝试** User.Identity.Name; ** – 2013-02-11 06:57:52

+0

是的,我正在访问它的操作方法,但它一直保持空白。 – ankur 2013-02-11 07:10:26

回答

-1

控制器你可以直接尝试 -

string user = User.Identity.Name; 
+0

它给空字符串 – ankur 2013-02-11 07:09:44

+0

你有没有在配置文件中指定? – ssilas777 2013-02-11 07:12:03

+0

@ankur整理出此??? – ssilas777 2013-02-11 12:34:10