2010-06-13 58 views

回答

2

目前的身份验证的用户应该分配给IPrincipal对身份的IIdentity名的HttpContext

HttpContext.Current.User.Identity.Name 

在ASP.NET MVC User属性,它是在控制器中可用的经由

this.User.Identity.Name 
+0

这就是我正在寻找的。谢谢。 – 2010-06-13 16:48:53

1

您不需要在会话中存储用户名 - 您的页面只需访问HttpContext的User属性。为了让你会用User.Identity.Name实际的用户名,并作为一个方便快捷的ASP.NET页面类本身有一个用户属性,所以你可以在你的代码做

string userName = Page.User.Identity.Name; 

后面。

如果您使用ASP.NET MVC有,你可以在控制器访问用户属性

string userName = User.Identity.Name 
+0

从MVC控制器怎么样? – 2010-06-13 16:24:11

相关问题