Vinicius Ottoni
Vinicius Ottoni

Reputation: 4677

My app keeps impersonating the user even when i put "false" in the web.config

Details of my app: - ASP.NET MVC 3 - Windows Authentication mode - IIS 6

So, in the web.config i put the impersonate to false, but when i try get the current user with Environment.UserName the app keeps getting the NETWORK SERVICE user. Why?

Upvotes: 1

Views: 155

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039278

To get the current user in an ASP.NET MVC application you should use the User.Identity.Name property:

public ActionResult Index()
{
    var currentUser = User.Identity.Name;
    return Content("current user: " + currentUser);
}

Environment.UserName gives you the account under which the application pool executes.

Also make sure that in IIS you have disabled anonymous authentication in the properties of the virtual directory and left only Windows authentication checked.

Upvotes: 2

Related Questions