Rehan Aslam
Rehan Aslam

Reputation: 241

Display all Session variables on a .cshtml page

What's the best way to display ALL session variables on a .cshtml page?

Tried using

@HttpContext.Current.Session();

But that didn't show anything.

Upvotes: 4

Views: 5791

Answers (1)

Mister Epic
Mister Epic

Reputation: 16743

This is untested, but should work:

@{ var session = HttpContext.Current.Session; }
@foreach (string key in session.Keys) {
    <p>Key: @key - Value: @session[key].ToString()</p>
}

Upvotes: 6

Related Questions