Getting username

V

Vik

An ASP.NET page uses Windows authentication method for the user log in. How
can get the username by code in this page?

Thanks.
 
R

Raterus

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

Guest

The easy version of the other two replies is just use something like this:

userName = User.Identity.Name;
 
N

Nicole Calinoiu

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top