asp.net 頁(yè)面回跳實(shí)現(xiàn)代碼
更新時(shí)間:2010年03月30日 13:05:46 作者:
今天做登錄時(shí),遇到點(diǎn)小問(wèn)題,在網(wǎng)上找了一下,沒(méi)看到源碼案例,不過(guò)還是花了一點(diǎn)時(shí)間調(diào)試通過(guò)了在此記錄一下,備忘。
主要是Request.UrlReferrer的用法
注意: 如果上一頁(yè)面使用document.location方法導(dǎo)航到當(dāng)前頁(yè)面,Request.UrlReferrer返回空值
如果有A,B兩個(gè)頁(yè)面,在瀏覽器中直接請(qǐng)求A頁(yè)面,在A頁(yè)面的中Page_Load事件中導(dǎo)航到B 頁(yè)面,
則 Request.UrlReferrer返回空。因?yàn)?在Page_load事件中頁(yè)面還未初始化,所以無(wú)法記錄當(dāng)前頁(yè)的信息,
導(dǎo)航到b頁(yè)面也就無(wú)法獲得上一頁(yè)面的信息
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.UrlReferrer != null)
{
ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
}
if (Session["user"] != null)
{
if (Request.UrlReferrer != null)
{
Response.Redirect(Request.UrlReferrer.ToString());
}
else
{
Response.Redirect("/");
}
}
username.Value = Request.Form["Uname"];
pass.Attributes.Add("value", Request.Form["password"]);
}
}
/// <summary>
/// 個(gè)人會(huì)員登陸
/// </summary>
protected void userLog()
{
Lovetrip.BLL.Manage.Users bllu = new Lovetrip.BLL.Manage.Users();
Lovetrip.Model.Manage.Users modeu = bllu.Login(username.Value.Trim(), pass.Text.Trim());
if (modeu != null)
{
Session["user"] = modeu;
Session["userType"] = 1;
Command.Public.MoveUserSession(1);
bbsLogin(modeu.unick);
if (Request.UrlReferrer != null)
{
Response.Redirect(ViewState["UrlReferrer"].ToString());
}
else
{
Response.Redirect("/");
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('帳號(hào)或密碼輸入有誤!')", true);
}
}
注意: 如果上一頁(yè)面使用document.location方法導(dǎo)航到當(dāng)前頁(yè)面,Request.UrlReferrer返回空值
如果有A,B兩個(gè)頁(yè)面,在瀏覽器中直接請(qǐng)求A頁(yè)面,在A頁(yè)面的中Page_Load事件中導(dǎo)航到B 頁(yè)面,
則 Request.UrlReferrer返回空。因?yàn)?在Page_load事件中頁(yè)面還未初始化,所以無(wú)法記錄當(dāng)前頁(yè)的信息,
導(dǎo)航到b頁(yè)面也就無(wú)法獲得上一頁(yè)面的信息
復(fù)制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.UrlReferrer != null)
{
ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
}
if (Session["user"] != null)
{
if (Request.UrlReferrer != null)
{
Response.Redirect(Request.UrlReferrer.ToString());
}
else
{
Response.Redirect("/");
}
}
username.Value = Request.Form["Uname"];
pass.Attributes.Add("value", Request.Form["password"]);
}
}
/// <summary>
/// 個(gè)人會(huì)員登陸
/// </summary>
protected void userLog()
{
Lovetrip.BLL.Manage.Users bllu = new Lovetrip.BLL.Manage.Users();
Lovetrip.Model.Manage.Users modeu = bllu.Login(username.Value.Trim(), pass.Text.Trim());
if (modeu != null)
{
Session["user"] = modeu;
Session["userType"] = 1;
Command.Public.MoveUserSession(1);
bbsLogin(modeu.unick);
if (Request.UrlReferrer != null)
{
Response.Redirect(ViewState["UrlReferrer"].ToString());
}
else
{
Response.Redirect("/");
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('帳號(hào)或密碼輸入有誤!')", true);
}
}
相關(guān)文章
ASP.NET預(yù)備知識(shí)學(xué)習(xí)筆記
這篇文章主要介紹了ASP.NET預(yù)備知識(shí),內(nèi)容很全面,幾乎涵蓋了asp.net預(yù)備知識(shí)點(diǎn),感興趣的小朋友可以看一看。2015-09-09asp.net中利用ashx實(shí)現(xiàn)圖片防盜鏈代碼
直接分析盜鏈原理:看下面用httpwatch截獲的http發(fā)送的數(shù)據(jù)2008-11-11如何對(duì)ASP.NET網(wǎng)站實(shí)現(xiàn)靜態(tài)化
對(duì)于訪問(wèn)量比較大的網(wǎng)站,網(wǎng)頁(yè)靜態(tài)化是一個(gè)比較可靠的解決方案。靜態(tài)化將顯著降低服務(wù)器的壓力,提升服務(wù)器處理能力。下面將介紹兩種不同的實(shí)現(xiàn)方法,并進(jìn)行對(duì)比。2015-09-09ASP.NET對(duì)路徑"xxxxx"的訪問(wèn)被拒絕的解決方法小結(jié)
異常詳細(xì)信息: System.UnauthorizedAccessException: 對(duì)路徑“D:/temp1/MyTest.txt”的訪問(wèn)被拒絕2012-09-09ASP.NETCore6開(kāi)啟文件服務(wù)允許通過(guò)url訪問(wèn)附件的操作方法
最近在做一個(gè)工作臺(tái)的文件上傳下載功能,主要想實(shí)現(xiàn)上傳圖片之后,可以通過(guò)url直接訪問(wèn),由于url直接訪問(wèn)文件不安全,所以需要手動(dòng)開(kāi)啟文件服務(wù),這篇文章主要介紹了ASP.NETCore6開(kāi)啟文件服務(wù)允許通過(guò)url訪問(wèn)附件,需要的朋友可以參考下2023-11-11