Go: Two ways to get Web page URL address and parameters (JS and C #)
A JS
Look at an example first
Using JavaScript to get URL URLs information
<script type= "Text/javascript" >
document.write ("location.host=" +location.host+ "<br>");
document.write ("location.hostname=" +location.hostname+ "<br>");
document.write ("location.href=" +location.href+ "<br>");
document.write ("location.pathname=" +location.pathname+ "<br>");
document.write ("location.protocol=" +location.protocol+ "<br>");
</script>
Execute the URL information code with JavaScript to get the following effect
location.host=www.vnde.cn
Location.hostname=www.vnde.cn
location.href=http://www.vnde.cn/bc/2008/0306/article_1860.html
Location.pathname=/bc/2008/0306/article_1860.html
location.protocol=http:
Detailed description of the Window.location method get URL
The full URL of the Uniform Resource Locator (Uniform Resource Locator, URL) consists of these parts:
Scheme://host:port/path?query#fragment
Scheme: Communication protocol
Common Http,ftp,maito, etc.
Host: Hosts
The server (computer) domain Name System (DNS) hostname or IP address.
Port: Port number
An integer, optionally, that omits the default port for using the scenario, such as HTTP, with the default port of 80.
Path: Paths
A string separated by 0 or more "/" symbols, typically used to represent a directory or file address on a host.
Query: Querying
Optional, for use with dynamic Web pages such as CGI, ISAPI, php/jsp/asp/asp. NET and other technical Web pages) pass parameters, can have multiple parameters, separated by the "&" symbol, the name and value of each parameter is separated by the "=" symbol.
Fragment: Pieces of information
String that specifies the fragment in the network resource. For example, there are multiple noun interpretations in a Web page, and you can use fragment to navigate directly to a noun interpretation. (also known as anchor points.)
Example:
1, Window.location.href
The entire URL string (in the browser is the full address bar)
return value: http://www.2astudio.com:80/view.asp?id=209#cmt1323
2,window.location.protocol
The protocol portion of the URL
Return value: http:
3,window.location.host
The host part of the URL,
return value: www.2astudio.com
4,window.location.port
The port portion of the URL. If you are using the default 80 port (update: Even if you added: 80), the return value is not the default of 80 but the null character.
This example returns the value: Empty
5,window.location.pathname
The path portion of the URL (that is, the file address)
return value:/view.asp
6,window.location.search
Query (Parameters) section. In addition to assigning values to dynamic languages, we can also give static pages and use JavaScript to get the values of the arguments we believe in.
Return value:? id=209
7,window.location.hash
Anchor Point
return value: #cmt1323
Two C #
The following table is a list of the properties and usages associated with the URL of the Browser Request:
| Website: Http://localhost:1897/News/Press/Content.aspx/123?id=1#toc |
| Request.applicationpath |
/ |
| Request.PhysicalPath |
D:\Projects\Solution\web\News\Press\Content.aspx |
| System.IO.Path.GetDirectoryName (Request.PhysicalPath) |
D:\Projects\Solution\web\News\Press |
| Request.physicalapplicationpath |
D:\Projects\Solution\web\ |
| System.IO.Path.GetFileName (Request.PhysicalPath) |
Content.aspx |
| Request.currentexecutionfilepath |
/news/press/content.aspx |
| Request.filepath |
/news/press/content.aspx |
| Request.path |
/news/press/content.aspx/123 |
| Request.rawurl |
/news/press/content.aspx/123?id=1 |
| Request.Url.AbsolutePath |
/news/press/content.aspx/123 |
| Request.Url.AbsoluteUri |
Http://localhost:1897/News/Press/Content.aspx/123?id=1 |
| Request.Url.Scheme |
http |
| Request.Url.Host |
localhost |
| Request.Url.Port |
1897 |
| Request.Url.Authority |
localhost:1897 |
| Request.Url.LocalPath |
/news/press/content.aspx/123 |
| Request.pathinfo |
/123 |
| Request.Url.PathAndQuery |
/news/press/content.aspx/123?id=1 |
| Request.Url.Query |
? id=1 |
| Request.Url.Fragment |
|
| Request.Url.Segments |
/ news/ press/ content.aspx/ 123 |
Two methods (JS and C #) to get URL addresses and parameters for Web pages