How to log out user from web site using BASIC authentication?

后端 未结 22 1474
感情败类
感情败类 2020-11-22 04:00

Is it possible to log out user from a web site if he is using basic authentication?

Killing session is not enough, since, once user is authenticated, each request co

22条回答
  •  攒了一身酷
    2020-11-22 04:46

    This is working for IE/Netscape/Chrome :

          function ClearAuthentication(LogOffPage) 
      {
         var IsInternetExplorer = false;    
    
         try
         {
             var agt=navigator.userAgent.toLowerCase();
             if (agt.indexOf("msie") != -1) { IsInternetExplorer = true; }
         }
         catch(e)
         {
             IsInternetExplorer = false;    
         };
    
         if (IsInternetExplorer) 
         {
            // Logoff Internet Explorer
            document.execCommand("ClearAuthenticationCache");
            window.location = LogOffPage;
         }
         else 
         {
            // Logoff every other browsers
        $.ajax({
             username: 'unknown',
             password: 'WrongPassword',
                 url: './cgi-bin/PrimoCgi',
             type: 'GET',
             beforeSend: function(xhr)
                     {
                xhr.setRequestHeader("Authorization", "Basic AAAAAAAAAAAAAAAAAAA=");
             },
    
                     error: function(err)
                     {
                        window.location = LogOffPage;
                 }
        });
         }
      }
    
    
      $(document).ready(function () 
      {
          $('#Btn1').click(function () 
          {
             // Call Clear Authentication 
             ClearAuthentication("force_logout.html"); 
          });
      });          
    

提交回复
热议问题