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 mvc中Forms身份驗(yàn)證身份驗(yàn)證流程
本篇文章主要介紹了asp.net MVC中Forms身份驗(yàn)證身份驗(yàn)證流程,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10
ASP.NET2.0中數(shù)據(jù)源控件之異步數(shù)據(jù)訪問(wèn)
ASP.NET2.0中數(shù)據(jù)源控件之異步數(shù)據(jù)訪問(wèn)...2006-09-09
SqlDataSource 鏈接Access 數(shù)據(jù)
如何用AccessDataSource鏈接有密碼的access數(shù)據(jù)庫(kù)總是會(huì)報(bào)錯(cuò),替代方法是用SqlDataSource 鏈接Access 數(shù)據(jù)。2009-04-04
EF?Core項(xiàng)目中不同數(shù)據(jù)庫(kù)需要的安裝包介紹
這篇文章介紹了EF?Core項(xiàng)目中不同數(shù)據(jù)庫(kù)需要的安裝包,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
asp.net下XML的加密和解密實(shí)現(xiàn)方法
xml加密(XML Encryption)是w3c加密xml的標(biāo)準(zhǔn)。這個(gè)加密過(guò)程包括加密xml文檔的元素及其子元素,通過(guò)加密,xml的初始內(nèi)容將被替換,但其xml格式仍然被完好的保留。2010-02-02
asp.net gridview實(shí)現(xiàn)全選,反選與刪除記錄的操作代碼
asp.net gridview實(shí)現(xiàn)全選,反選與刪除記錄的操作代碼,需要的朋友可以參考下。2011-07-07
asp.net使用ajaxFileUpload插件上傳文件(附源碼)
本文詳細(xì)講解了asp.net使用ajaxFileUpload插件上傳文件,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12
.Net彈性和瞬態(tài)故障處理庫(kù)Polly介紹
這篇文章介紹了.Net彈性和瞬態(tài)故障處理庫(kù)Polly,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06

