In an mvc .net web application that uses forms authentication, how to know the current user identity in controllers?
Asked
Active
Viewed 204 times
2 Answers
2
You could use User.Identity.Name:
[Authorize]
public ActionResult SomeAction()
{
string currentlyLoggedInUsername = User.Identity.Name;
...
}
Darin Dimitrov
- 994,864
- 265
- 3,241
- 2,902
0
this.HttpContext.User.Identity
Note that you should also check if
this.HttpContext.User.Identity.IsAuthenticated
to distinguish between anonymous and authenticated users.
Wiktor Zychla
- 45,537
- 6
- 71
- 97