John Livermore
John Livermore

Reputation: 31313

How to tell if ASP.NET impersonation is working?

With ASP.NET impersonation, can one use Environment.UserName to determine if impersonation is working? That is if the site is impersonating properly, should Environment.UserName return my username?

Upvotes: 2

Views: 521

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

You should use User.Identity.Name:

[Authorize]
public ActionResult Foo()
{
    // If we got so far it means that the user is authorized to 
    // execute this action according to our configuration => 
    // we can work with his username
    string username = User.Identity.Name;
    ...
}

Upvotes: 2

Related Questions