Getting username

  • Thread starter Thread starter Nicole Calinoiu
  • Start date Start date
An ASP.NET page uses Windows authentication method for the user log in. How
can get the username by code in this page?

Thanks.
 
"HttpContext.Current.User" WILL contain the identity you want if you are using windows authentication.
 
The easy version of the other two replies is just use something like this:

userName = User.Identity.Name;
 
That depends on what you mean by "using Windows authentication". Having an
<authentication mode="Windows" /> element in your web.config file is not, in
and of itself, sufficient to make an authenticated user identity end up in
HttpContext.Current.User. See, for example, the IIS anonymous
authentication of the P&P document at
http://msdn.microsoft.com/library/en-us/dnnetsec/html/SecNetAP05.asp.

Also, if someone needs to ask the question, they generally are unaware that
multiple user identities may be implicated. Are you sure OP merely wants
the user name provided? What if the real intent is to determine why trusted
connections to SQL Server are failing when it is supposed that the
credentials being passed are those of the authenticated user? The
HttpContext user wouldn't help one bit with this...


"HttpContext.Current.User" WILL contain the identity you want if you are
using windows authentication.
 
Back
Top