Alexander Talavari
Alexander Talavari

Reputation: 418

Show logged in user data asp.net mvc

Which is the best way to expose current logged in user data to many different views?

I am thinking something like the Model variable but accessible to all view but wasn't able to find any documentation.

Upvotes: 0

Views: 371

Answers (1)

Rowan Freeman
Rowan Freeman

Reputation: 16398

You an access the user property from any view with

@User

For example (C#),

@{
    if (User.Identity.IsAuthenticated)
    {
        <p>Hello, @User.Identity.Name</p>
    }
}

Upvotes: 1

Related Questions