Gets the URL of the current request page and the source URL

Source: Internet
Author: User
Tags servervariables

Request.url gets the URL of the current request page

Request.urlreferrer or request.servervariables["Http_referer"] can get the source URL

Default.aspx code

<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default.aspx.cs" Inherits = "_default"%&G T

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt D ">

< html xmlns = "http://www.w3.org/1999/xhtml" >
< head runat = "server" >
< title > Untitled page </title >
< BODY >
< form ID = "Form1" runat = "server" >
< div >
Request.url Gets the URL < asp:label ID = "Label1" runat = "server" Text = "Label" ></Asp:label >< BR for the current page />
Request.urlreferrer Gets the URL < Asp:label ID of the previous page = "Label2" runat = "server" Text = "Label" ></Asp:label ;< br/>
Request.ServerVariables Collection Gets the previous page URL < Asp:label ID = "Label3" runat = "server" Text = "Label" ></Asp:lab El ></div >
</form >
</Body >
</HTML >

Default.aspx.cs Code

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

public partial class _default:system.web.ui.page
... {
protected void Page_Load (object sender, EventArgs e)
... {
Label1.Text = Request.Url.ToString ();
if (request.urlreferrer!= null)
... {
Label2.Text = Request.UrlReferrer.ToString ();
Label3.text = request.servervariables["Http_referer"]. ToString ();
}

}
}

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.