Turn: Get the address of the web page URL and parameters of the two methods (js and C #)
A js
Look at an example
Get url URL information with javascript
<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>
URL url information acquisition performed by the code effect as javascript
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:
Details window.location method to get the URL
The full Uniform Resource Locator URL (Uniform Resource Locator, URL) consists of several parts:
scheme://host:port/path?query#fragment
scheme: Communication Protocol
Commonly used http, ftp, maito etc.
host: Host
Server (computer) domain name system (DNS) host name or IP address.
port: port number
Integer, alternatively, using the default port scheme is omitted, as is the default http port 80.
path: the path
It consists of zero or more "/" symbol string spaced, generally used to indicate a file or directory on the host address.
query: Query
Alternatively, for a dynamic web page (e.g., using technology to produce CGI, ISAPI, PHP / JSP / ASP / ASP.NET pages, etc.) to pass parameters, there may be multiple parameters, with the "&" symbol spaced, each parameter the name and value separated by "=" symbol.
fragment: pieces of information
String that specifies the network resource in pieces. A plurality of pages, for example, noun, targeting fragment can be used directly to a noun. (Also known as the anchor.)
Example:
1, window.location.href
URl whole string (in the browser address bar is full)
Return value: http: //www.2astudio.com: 80 / view.asp id = 209 # cmt1323?
2,window.location.protocol
Protocol part of the URL
Return value: http:
3,window.location.host
Host part of the URL,
Return value: www.2astudio.com
4,window.location.port
Port portion of the URL. If you use the default port 80 (update: Even added: 80), the return value is not the default 80 but the null character.
This Example Return Value: None
5,window.location.pathname
Path portion of the URL (the address is file)
Return value: /view.asp
6,window.location.search
Query (parameters) section. In addition to the assignment to the dynamic language, we can also give a static page and use javascript to get the parameter values corresponding to believe
Return value:? Id = 209
7,window.location.hash
Anchor
Return value: # cmt1323
Two C #
This table is under various attributes and usage with Browser Request URL related to:
网址: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 |