asp.net tips and tricks

How to get the username in a web app

Four steps to achieve it:

  1. Use the following code to get the username in your application:
    string user = User.Identity.Name.ToString();
  2. Modify your web.config file to include the identity and the authentication tags:
    <system.web>        
            <identity impersonate="true" />
            <authentication mode="Windows"/>
    </system.web>
  3. In IIS right click your application and select Properties. Go to the Directory Security tab. Click Edit under Authentication and Access Control. Uncheck Enable anonymous access and check Integrated Windows authentication. Click Ok to save your changes.
  4. Open Windows Explorer, go to your application folder and modify permissions to allow your users (and not the IIS anonymous user) access your application.

Leave a Reply