avatar

Andres Jaimes

asp.net tips and tricks

By Andres Jaimes

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();
  1. Modify your web.config file to include the identity and the authentication tags:
<system.web>        
        <identity impersonate="true" />
        <authentication mode="Windows"/>
</system.web>
  1. 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.
  2. Open Windows Explorer, go to your application folder and modify permissions to allow your users (and not the IIS anonymous user) access your application.