Vishwakant Tripathi

Vishwakant Tripathi

  • 1k
  • 721
  • 838.4k

How to get user name in Windows Authentication

Oct 11 2013 2:51 AM

Hi,

        I am working on a web application with windows authentication mode. I set it in web.config...

 <authentication mode="Windows"></authentication>
    <identity impersonate="false"></identity>

When I run application, it ask for user name and password, I put my system username and password, and It get me logged in successfully.

I am trying to access current username in my application, but I am not getting what I entered, it gave me NT AUTHORITY\SYSTEM as user name.

One more thing, If i run application through Visual Studio, it gives me correct user name, but through IIS, I browse it, it does not give correct user name.

Below is the code that I have written to get current user name..

System.Security.Principal.WindowsIdentity.GetCurrent().Name

But it's not giving my system user name.

I am using application pool with v4.0, Integrated and Local System Identity.

Can any one please help me how to get current user name.

Thanks

VD


Answers (1)