Session C # how does it work?

2

What is the lifetime of a Session in ASP.NET MVC, and how do I find out how much time is remaining and how to add more Session time (if at all possible)?

Is there another form of value guarding that is more performative?

    
asked by anonymous 02.03.2016 / 19:10

2 answers

3

Possibly duplicate? (This link can also help you) What's the difference between Sessions and Cookies?

For web, you can change the timeout value of the session through web.config :

<configuration>
  <system.web>
     <sessionState timeout="20"></sessionState>
  </system.web>
</configuration>

By default, the time is 20 minutes. As for getting the remaining time to finish the session, there are several ways you would have to be more specific in regards to this. One solution would be to control the time via javascript. But if you want, for example, to redirect the user after the session is finished, you can use HttpContext.Current.User.Identity.IsAuthenticated and do such validation.

EDIT:

No, as far as I know, it is not possible to change session time in real-time , since we are talking about downtime. You set the maximum inactivity time and, after that time, the session is terminated.

You can implement a solution to keep your session alive for an indefinite period, just "mix" an action in the MVC and make the call via jQuery:

[HttpPost]
public JsonResult KeepSessionAlive() {
    return new JsonResult {Data = "Success"};
}
    
02.03.2016 / 21:10
0

What would a session of a system be?

Session is generally used to store user data. It is done this way because the data stays in the server, not allowing other users to have access.

You can save the session of your application in several ways:

InProc: stores session state in Web server memory. This is the default.

StateServer: Stores session state in a separate process called the ASP.NET state service. This ensures that session state is preserved if the Web application is restarted and also causes session state to be available to multiple Web servers in a Web farm ..

SQLServer: Stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also causes session state to be available to multiple Web servers in a Web farm ..

Custom: allows you to specify a custom storage provider.

Off: No session.

link

Depending on your system you will need a different way.

Regarding the cycle to life, the user session is deleted when the user logs off the system.

I would like to make a reservation, it is not necessary to use Session you can very well store the information in encrypted form in the browser cookie.

Following is an exept tutorial by Eduardo Pires MVP

link

    
04.03.2016 / 12:41