2010-06-13 27 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

相關問題