In fact, the method is the same as the method for obtaining the origin address of the page.
String strrequestfrom = "";
If (httpcontext. Current. Request. urlreferrer = NULL)
{
Strrequestfrom = "direct access ";
}
Else
{
Strrequestfrom = httpcontext. Current. Request. urlreferrer. absoluteuri;
}
Lazy writing using the three-object OPERATOR:
String strrequestfrom = httpcontext. Current. Request. urlreferrer = NULL? "Direct access": httpcontext. Current. Request. urlreferrer. absoluteuri;
Introduction to urlreferrer
Obtain information about the URL of the client's last request. The request is linked to the current URL.
Namespace: system. Web
ProgramSet: system. Web (in system. Web. dll)
Syntax
C #
Public URI urlreferrer {Get ;}
Attribute Value
A URI object.
Example
The followingCodeThe example shows the two property values that reference the client to the URL of the current application.
Uri myurl = request. urlreferrer;
Response. Write ("referrer URL port:" + server. htmlencode (myurl. Port. tostring () + "<br> ");
Response. Write ("referrer URL protocol:" + server. htmlencode (myurl. Scheme) + "<br> ");
Uri. absoluteuri Property
Obtain the absolute Uri.
Namespace: System
Assembly: system (in system. dll)
Syntax
C #
Public String absoluteuri {Get ;}
Attribute Value
String that contains the entire Uri.
Remarks
The absoluteuri attribute includes the entire URI stored in the URI instance, including all fragments and query strings.
Example
The following example outputs the complete content of the URI instance to the console. In the example, http://www.contoso.com/catalog/shownew.htm? Date = today will be output to the console.
C #
Uri baseuri = new uri ("http://www.contoso.com ");
Uri myuri = new uri (baseuri, "catalog/shownew.htm? Date = Today ");
Console. writeline (myuri. absoluteuri );