Client Side Session Redirection in ASP.Net

I want to create a way to automatically redirect users to Timeout.aspx when their session expires due to inactivity. My application uses form authentication and relies heavily on the update panel on the same aspx page to interact with the user, so I don't want to just redirect after the page level timer has expired. For the same reason, I cannot use '<meta http-equiv = "refresh" />'

I want to create a simple ajax web service using the IsSessionTimedOut () method, which simply returns a boolean. I will use the javascript timer to periodically call the method, and if it returns true, redirect it to Timeout.aspx. However, I do not want to call this method until the session timeout timer is reset, or the session will never timeout due to a service call. Is there a clean way to avoid this catch-22? Hopefully there is a simple solution that has eluded me so far.

+3
source share
5 answers

, AJAX script , , - /. script , .

.

, .

/ .

; : Ajax, - , ; -)

AsynchronousSessionAuditor 1.0

+9

, , - . , 15- javascript, reset async. , , , , .

. javascript reset, , :

        <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError">
        <Scripts >
            <asp:ScriptReference Path="~/scripts/jquery/jquery-1.3.2.min.js" />
        </Scripts>
        </asp:ScriptManager>

        <script type="text/javascript">

        var redirectTimer = setTimeout('redirectToLogout()', 900000);

        function redirectToLogout() {
            window.location = "/logout.aspx";
        }

        function ResetTimeoutTimer() {
            clearTimeout(redirectTimer);
            redirectTimer = setTimeout('redirectToLogout()', 900000);
        }


        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ResetTimeoutTimer);

       </script>
+2

, - , ?

, window.setTimeout() Timeout.aspx . Timeout.aspx Session.Abort(), , , .

, , , ( ) .

0

, ... ( ), , AJAX , , . ? UpdatePanel... , , " pardner, "?

0

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


All Articles