asp.net 頁面回跳實現(xiàn)代碼
更新時間:2010年03月30日 13:05:46 作者:
今天做登錄時,遇到點(diǎn)小問題,在網(wǎng)上找了一下,沒看到源碼案例,不過還是花了一點(diǎn)時間調(diào)試通過了在此記錄一下,備忘。
主要是Request.UrlReferrer的用法
注意: 如果上一頁面使用document.location方法導(dǎo)航到當(dāng)前頁面,Request.UrlReferrer返回空值
如果有A,B兩個頁面,在瀏覽器中直接請求A頁面,在A頁面的中Page_Load事件中導(dǎo)航到B 頁面,
則 Request.UrlReferrer返回空。因為 在Page_load事件中頁面還未初始化,所以無法記錄當(dāng)前頁的信息,
導(dǎo)航到b頁面也就無法獲得上一頁面的信息
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>
/// 個人會員登陸
/// </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('帳號或密碼輸入有誤!')", true);
}
}
注意: 如果上一頁面使用document.location方法導(dǎo)航到當(dāng)前頁面,Request.UrlReferrer返回空值
如果有A,B兩個頁面,在瀏覽器中直接請求A頁面,在A頁面的中Page_Load事件中導(dǎo)航到B 頁面,
則 Request.UrlReferrer返回空。因為 在Page_load事件中頁面還未初始化,所以無法記錄當(dāng)前頁的信息,
導(dǎo)航到b頁面也就無法獲得上一頁面的信息
復(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>
/// 個人會員登陸
/// </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('帳號或密碼輸入有誤!')", true);
}
}
相關(guān)文章
如何對ASP.NET網(wǎng)站實現(xiàn)靜態(tài)化
對于訪問量比較大的網(wǎng)站,網(wǎng)頁靜態(tài)化是一個比較可靠的解決方案。靜態(tài)化將顯著降低服務(wù)器的壓力,提升服務(wù)器處理能力。下面將介紹兩種不同的實現(xiàn)方法,并進(jìn)行對比。2015-09-09ASP.NET對路徑"xxxxx"的訪問被拒絕的解決方法小結(jié)
異常詳細(xì)信息: System.UnauthorizedAccessException: 對路徑“D:/temp1/MyTest.txt”的訪問被拒絕2012-09-09ASP.NETCore6開啟文件服務(wù)允許通過url訪問附件的操作方法
最近在做一個工作臺的文件上傳下載功能,主要想實現(xiàn)上傳圖片之后,可以通過url直接訪問,由于url直接訪問文件不安全,所以需要手動開啟文件服務(wù),這篇文章主要介紹了ASP.NETCore6開啟文件服務(wù)允許通過url訪問附件,需要的朋友可以參考下2023-11-11