Thursday, November 29, 2012

Get Windows User ASP.NET


When developing ASP.NET applications, there might be situations where you need to know who is the currently logged in Windows user in to do things like authorization, authentication etc. These might b e useful when you are developing applications for the internal use within an organization. 

Luckily ASP.NET has few options built in to get the currently logged in user. You can use one of the following code snippet to get the current user.

1.

string user = HttpContext.Current.User.Identity.Name;


2. 

string user = Thread.CurrentPrincipal.Identity.Name;

2nd opiton only applies when you have specified in your web applications config file that the authentication mode is windows 

This is pretty straight forward and simple. 



No comments:

Post a Comment