2016-07-21 17 views
-1

私はWeb開発と.NETについても新しいです。私はC#を使用してASP.NETで書かれたWebサイトを持っています。セッションを使用しているユーザー名ではなく、現在のユーザーのフルネームを表示するにはどうすればよいですか?私を助けてください。ここにコードがあります。ログインページの背後にあるユーザ名の代わりに表示名を表示する方法#

コード: -

System.Security.Principal.WindowsPrincipal username = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal; 
    string userName = username.Identity.Name; 

    if (username.Identity.IsAuthenticated) 
    { 
     Session["logged"] = userName; 
     agentname.Text = Session["logged"].ToString(); 
    } 
    else 
    { 
     agentname.Text = "You are not loggd in please logine first "; 
    } 
    if (Session["logged"] == null) 
    { 
     agentname.Text = "You are not loggd in please login first "; 
    } 
    else 
    { 
     agentname.Text = Session["logged"].ToString(); 
    } 

答えて

1

それは動作しますが、これを使用してください。私はあなたがWindows認証を使用していると仮定しています。それがあなたのために働くなら、答えとしてそれをマークして、他の人がそれを見てそれから助けを得るでしょう。

using System.DirectoryServices.AccountManagement; 

    string name = UserPrincipal.Current.GivenName + " " + UserPrincipal.Current.Surname; 
関連する問題