我有這樣的aspx代碼在這裏:如何在會話過期前保持同一頁面?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MSSQLConnector;
using System.Data;
using System.Data.SqlClient;
namespace SoftwareAnalysisAndDesign.SAD
{
public partial class AdministratorPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//If user run this page without logging in, it will redirect the user to the login page
if (Session["adminlogin"] == null)
{
Response.Redirect("LoginPage.aspx", true);
}
}
}
}
當我直接去管理頁面時,會爲空就會去到登錄頁面。但是當我使用用戶名和密碼登錄時,系統會給我一條消息「瀏覽器有一個重定向循環」。當我按下瀏覽器後退按鈕時,應該使我的AdminPage保持在同一頁面上的過程是什麼,它只會進入LoginPage,會話爲空或會話由註銷事件處理程序終止。或者,如果用戶按下了網絡瀏覽器返回按鈕,系統將通過是或否的決定提醒用戶「您要註銷」。如果沒有系統將保持在同一頁面上,如果是,則會話將被終止並且系統重定向到登錄頁面。
我的登錄頁面代碼:
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using MSSQLConnector;
using System.Data;
namespace SoftwareAnalysisAndDesign.SAD
{
public partial class OnlineAppSyss : System.Web.UI.Page
{
public void Admin()
{
//String decleration
string adminusername = (this.UserName.Value);
string adminpass = (this.Password.Value);
try
{
if (adminusername == "admin" && adminpass == "cmpe1234")
{
Session["adminlogin"] = adminusername;
Response.Redirect("AdministratorPage.aspx");
}
else
{
Response.Write("<script language=javascript>alert('Username and password does not match. Try again');</script>");
}
}
catch
{
Response.Write("<script language=javascript>alert('Username and password does not match. Try again');</script>");
}
}
}
您是否已經在管理員頁面上?在這種情況下,'else'子句可能會不斷地重定向。嘗試不使用'else' ... –
我嘗試過,沒有其他功能先生,但系統會將頁面重定向到登錄頁面,但會話仍處於活動狀態。只希望我的系統在會話終止時只登錄登錄頁面。 –
我編輯了我的帖子先生。 –