2017-01-02 34 views
0

我有網頁顯示DB值(網格視圖),我可以編輯。 我的問題是:編輯後,如果我註銷頁面,它記錄了我出去,但如果我再次把該頁面的網址在瀏覽器,頁面重新載入,而不是再次要求我登錄。網頁URL帶來這已經是網頁登出:asp.net C#(沒有後退按鈕,但頁面URL)

ASP.NET代碼:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Logout.master.cs" Inherits="Logout" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <asp:ContentPlaceHolder id="head" runat="server"> 
    </asp:ContentPlaceHolder> 
</head> 
<body> 
    <form id="form1" runat="server"> 

     <asp:Label ID="Label1" Text="Loggin Out Please Wait.." runat="server" /> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 
    <div> 
     <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
      <ContentTemplate> 
       <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"> 
       </asp:Timer> 
      </ContentTemplate> 
     </asp:UpdatePanel> 
     <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> 

     </asp:ContentPlaceHolder> 
    </div> 
    </form> 
</body> 
</html> 

C#代碼:

protected void Timer1_Tick(object sender, EventArgs e) 
    { 
     Session.Clear(); 
     Session.Abandon(); 
     Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); 
     Response.Cache.SetCacheability(HttpCacheability.NoCache); 
     Response.Cache.SetNoStore(); 

     try 
     { 
      Session.Abandon(); 
      FormsAuthentication.SignOut(); 
      Response.Cache.SetCacheability(HttpCacheability.NoCache); 
      Response.Buffer = true; 
      Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d); 
      Response.Expires = -1000; 
      Response.CacheControl = "no-cache"; 
     } 
     catch (Exception ex) 
     { 
      Response.Write(ex.Message); 
     } 
     Response.Redirect("~/Login.aspx"); 
    } 

回答

0

在頁面加載,你必須看到的網頁是開放的第一time..if你,重定向到登錄頁面。所以,你必須在頁面加載 Page_Load中添加statment。 如果(ispostback) Responce.redirect(login.aspx) 或者(!Ispostback)im不確定哪一個

相關問題