In an mvc .net web application that uses forms authentication, how to know the current user identity in controllers?
Asked
Active
Viewed 215 times
2 Answers
2
You could use User.Identity.Name
:
[Authorize]
public ActionResult SomeAction()
{
string currentlyLoggedInUsername = User.Identity.Name;
...
}

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
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
- 47,367
- 6
- 74
- 106