Asp.net session expiry redirect to login page

前端 未结 5 1704
一整个雨季
一整个雨季 2020-12-20 08:28

What is the best way to redirect to the login page when the session expires. I\'m using

sessionState mode=\"InProc\"

Can I set this in the

5条回答
  •  有刺的猬
    2020-12-20 08:34

    One option instead of setting a client side timer to blindly redirect, is to have the timer hit a small webservice which could indicate if the user should be redirected. What this does is give you a lot more flexibility you could redirect a user under many cases including:

    • Session Expired
    • Same user account logged in from another machine
    • Site is going into to maintneance mode and you want to kick users out.

    I've used this method with a lot of success, for handling multiple user accounts. As for handling session you'd prolly want to listen for the session timeout even then store in a hash table whose session timed out.

    When that user calls the web service you remove them from the hash and tell the client code to redirect them.

    Another nice thing about this type of system is you can track when the browser hits the server, so you can get a better sense of who is still online.

    EDIT

    In Response to Comment Bellow:

    I don't think calling a public method would be cleaner. As soon as you do this you make an assumption that all pages share a single master page or common base class. I wouldn't want to make that assumption. Additionally, if you intend to use the PageMethods approach this won't work since PageMethods must be static.

    I'm not exactly sure what your intention is but if you were going to call this method on each request then I would do that using a http module and hook into the pipeline; however, this only works when a request is made. By using a web service with a client side timer you can redirect the user even if they are not making any requests.

提交回复
热议问题