Accessing a Session object from Razor _Layout.cshml

You could just access the HttpContext in the layout file

@HttpContext.Current.Session["Whatever"].ToString()

or, if you want access to the user object you could just create an object in the page and assign it

@{ CurrentUser user = (CurrentUser)HttpContext.Current.Session["CurrentUser"]; }

Then later in your code…

@user.Name

Leave a Comment