How to get the user name in a web app
Four steps to achieve it:
- Use the following code to get the user name in your application:
string user = User.Identity.Name.ToString();
- Modify your web.config file to include the identity and the authentication tags:
<system.web> <identity impersonate="true" /> <authentication mode="Windows"/> </system.web>
- 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.
- Open Windows Explorer, go to your application folder and modify permissions to allow your users (and not the IIS anonymous user) access your application.