Sample asp.net mvc session

can someone give me an example or link to one of the sessions in asp.net mvc?

+3
source share
2 answers

Same as WebForms:

Use the HttpContext.Current.Session object.

HttpContext.Current.Session["UserName"] = "Jon";

string userName = HttpContext.Current.Session["UserName"];
+10
source

With MVC Future, it can be made much easier.

Add one line in Global.asax.csto the Application_Start()method

ValueProviderFactories.Factories.Add(new SessionValueProviderFactory());

Then you can access the session in the controller using

$Session["YourName"] = "some value";

or in view

@Session["YourName"]

here is an article on how to add a library to you project

0
source

Source: https://habr.com/ru/post/1713841/


All Articles