2015-04-06 46 views
1

在我的项目中,我正在使用Windows身份验证登录。 注销按钮是必需的。如何在asp.net应用程序中注销按钮Windows身份验证

如果单击注销按钮页应重定向到Logout.aspx。 在Logout.aspx中,如果我在返回重定向的浏览器中按下后退按钮。

如何控制不应该重定向回在登录页面并要求窗口认证登录?

回答

0

我对此有一个网页形式的解决方案,你可以使用它,我希望是有用您。

logout.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="logout.aspx.cs" Inherits="logout" %> 

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <meta http-equiv="Cache-Control" content="no-cache"> 
    <meta http-equiv="Pragma" content="no-cache"> 
    <meta http-equiv="Expires" content="0"> 
</head> 
<body> 
    <script type="text/javascript"> 
     function HandleResult(arg, context) { 
      window.location = "/Login.aspx"; 
     } 
    </script> 
    <form id="form1" runat="server"> 
    </form> 
    <script> 
     CallServer('LoGout', ''); 
      var Backlen=history.length; 
     history.go(-Backlen); 
     window.location.href = "/Login.aspx"; 

    </script> 
</body> 
</html> 

logout.cs在我的项目

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 


public partial class logout : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler 
{ 
    public void RaiseCallbackEvent(string eventArgument) 
    { 
    } 

    public string GetCallbackResult() 
    { 
     return ""; 
    } 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     ClearAll(); 
     ClientScriptManager cm = Page.ClientScript; 
     string cbReference = cm.GetCallbackEventReference(this, "arg", "HandleResult", ""); 
     string cbScript = "function CallServer(arg, context){" + cbReference + ";}"; 
     cm.RegisterClientScriptBlock(this.GetType(), "CallServer", cbScript, true); 
     cm.RegisterStartupScript(this.GetType(), "cle", "windows.history.clear", true); 
     Response.Redirect("/login.aspx"); 

    } 
    protected void Page_Init(object sender, EventArgs e) 
    { 
     ClearAll(); 
    } 

    void ClearAll() 
    { 
     Session.RemoveAll(); 
     System.Web.Security.FormsAuthentication.SignOut(); 
     Response.Cache.SetCacheability(HttpCacheability.NoCache); 
     Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1)); 
     Response.Cache.SetNoStore(); 


    } 
} 

我有这个是工作的罚款。

+0

非常感谢你在windows身份验证 登录页面不可用 – 2015-04-07 12:44:15

+1

你能帮我我登录页面代码如何在Windows身份验证中使用? – 2015-04-07 12:46:24

+0

@HarshNag,我不明白你的意思,当然是为什么不,只是告诉我为什么你的登录页面不可用?!你可以上传你的Web应用程序样本,因为我不知道你有什么和你想要做什么。 – 2015-04-07 12:58:06

5

在Windows身份验证中,不存在注销的可能性,因为您没有使用IIS进行身份验证。您正在使用该操作系统,即使您在同一个浏览器中注销,然后在下一个请求中,您将自动在同一浏览器中登录。

所以在Windows auhtentication中不可能注销。

在堆栈溢出中看到同样的问题。

ASP.NET Windows Authentication logout

+0

我知道在使用Windows身份验证时不可能注销,但是可以强制用户使用浏览器登录页面重新输入凭据吗?必须有办法这样做,对吧?我曾尝试像document.execCommand('ClearAuthenticationCache',false)这样的技巧,但它不起作用。一旦用户第一次登录,我无法显示登录页面以便在需要时显示。 – MHOOS 2018-02-26 18:46:13

0

使用这个脚本在每个.aspx页面中

<script type = "text/javascript" > 
 
     function changeHashOnLoad() { 
 
      window.location.href += "#"; 
 
      setTimeout("changeHashAgain()", "50"); 
 
     } 
 

 
     function changeHashAgain() { 
 
      window.location.href += "1"; 
 
     } 
 

 
     var storedHash = window.location.hash; 
 
     window.setInterval(function() { 
 
      if (window.location.hash != storedHash) { 
 
       window.location.hash = storedHash; 
 
      } 
 
     }, 50); 
 

 

 
</script>

+0

非常感谢你 – 2015-04-07 12:44:04

相关问题