Implementation Code of asp.net page redirection

Source: Internet
Author: User

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 );
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.