Google Analytics İzleme

24 Ağustos 2009

Asp.Net'de oturum açan NT kullanıcı adını tespit etme

Getting the User Name :

using three ways we can get the User Name using C#

1) System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;

string strName = p.Identity.Name;

[ OR ]

2) string strName = HttpContext.Current.User.Identity.Name.ToString();

[ OR ]

3) string strName = Request.ServerVariables["AUTH_USER"]; //Finding with name

string strName = Request.ServerVariables[5]; //Finding with index

In Above 3 Cases returnin string contains DomainName\WinNTLoggedUserName

(for Ex: Microsoft\Bill.Gates. Here Microsoft is domain Bill.Gates is Logger User Name )

Using string operations seperate the DomainName and UserName.

kaynak:

http://www.codeproject.com/KB/aspnet/How_to_NT_User_Name.aspx


Hiç yorum yok: