2012-02-27 85 views

回答

3

在asp.net中有一個login name控件來顯示這些信息。只需將它放在您的母版頁上,如下所示:

<asp:LoginView runat="server"> 
    <LoggedInTemplate> 
     Welcome <asp:LoginName runat="server" /> 
    </LoggedInTemplate> 
</asp:LoginView> 

它只顯示登錄用戶的登錄名。

如果你到別的地方需要這些信息,你可以使用當前用戶身份使用來獲取名稱當前http context

if (HttpContext.Current.User.IsAuthenticated) 
{ 
    string currentUserName = HttpContext.Current.User.Identity.Name; 
} 
-2

你可以做的是在母版定義一個新的文本,並在登錄時保存用戶名insode這個文字並添加它之前歡迎

+0

最糟糕的做法 – Sly 2012-02-27 10:55:59

+0

@Ali Issa沒有辦法「保存」字面內的用戶名。如果有標籤控件和LoginView控件,爲什麼要使用文字? – AlfeG 2012-02-27 10:58:20