Mainly Request. UrlReferrer usage
Note: If the document. location method is used on the previous page to navigate to the current page, Request. UrlReferrer returns a null value.
If there are two pages A and B, directly request page A in the browser and navigate to page B in the Page_Load event of page,
Request. UrlReferrer returns NULL. The page information of the current page cannot be recorded because the page has not been initialized in the Page_load event,
If you navigate to page B, you cannot obtain the information on the previous page.
Copy codeThe Code is as follows:
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>
/// Personal member login
/// </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 ('account or password entered incorrectly! ') ", True );
}
}