0

I am here to find some expert tips about handling session in an MVC application.

Basically, what should be done to avoid null session crashes that log errors in event log in a request? (Normal and Ajax) In a normal request, i tend to redirect the user to a specific page telling him the session went out but is that ok? Also, how would you handle a null session in an ajax call knowing you cant simply redirect the user (without having to manually develop something on the client side to handle it)?

The problem is that it generate errors in the event log each time that happen. With enough charge, this lead to a lots of errors.

Rushino
  • 9,415
  • 16
  • 53
  • 93
  • Why are your sessions null? Is it a matter of user inactivity? If so, that is a security feature and should be used to log a user out after x amount of time. A null in an ajax call should just send back either the url to your log out page or some kind of error message indicating to the client side ajax call that you should redirect over to your log out page. – Ryan Wilson Jul 20 '18 at 12:06
  • Its due to user inactivity but in the context of a mobile device. However, on the client-side this kind of response aren't handled. They are Ajax call that load a partial view, if i redirect to another page, this redirection will lead to logout page content sent as result which is not exactly the intended behavior. We can't add client-side logic to handle this as no more developement on client-side are permitted. – Rushino Jul 20 '18 at 12:53
  • From what I have found, I don't think you can redirect an ajax call from the server side, so if you can't modify the front end code, I'm not sure if there is much you can do other than return a 500 status error on Ajax calls or possibly create a Partial View that looks like your log out page, or maybe better still, a Partial View which tells the user that their session expired and a link to the login page or something..(https://stackoverflow.com/questions/6611249/jquery-ajax-and-redirect-response-from-server) – Ryan Wilson Jul 20 '18 at 13:17

0 Answers0