ASP.NET MVC Session Expiration

前端 未结 6 2019
孤街浪徒
孤街浪徒 2021-01-01 21:51

We have an internal ASP.NET MVC application that requires a logon. Log on works great and does what\'s expected. We have a session expiration of 15 minutes. After sitting on

6条回答
  •  無奈伤痛
    2021-01-01 22:25

    My solution uses one meta-tag on login form and a bit of Javascript/jQuery.

    LogOn.cshtml

    
      
        
        ...
      
      ...
    
    

    Common.js

    var Common = {
        IsLoginForm: function (data) {
            var res = false;
    
            if (data.indexOf("__loginform__") > 0) {
                // Do a meta-test for login form
                var temp =
                    $("
    ") .html(data) .find("meta[data-name='__loginform__']") .attr("content"); res = !!temp; } return res; } };

    AJAX code

    $.get(myUrl, myData, function (serverData) {
        if (Common.IsLoginForm(serverData)) {
            location.reload();
            return;
        }
    
        // Proceed with filling your placeholder or whatever you do with serverData response
        // ...
    });
    

提交回复
热议问题