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