惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Fortinet All Blogs
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
小众软件
小众软件
有赞技术团队
有赞技术团队
雷峰网
雷峰网
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
AWS News Blog
AWS News Blog
C
Cisco Blogs
美团技术团队
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
W
WeLiveSecurity
D
DataBreaches.Net
博客园 - 司徒正美
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
Vercel News
Vercel News
月光博客
月光博客
T
Tailwind CSS Blog
H
Help Net Security
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
V2EX
WordPress大学
WordPress大学
Cyberwarzone
Cyberwarzone
Recent Announcements
Recent Announcements

博客园 - 微雨杏花村

CentOS firewalld 防火墙操作 CentOS 安装 dotnetcore CentOS7防火墙设置--iptables CentOS7.0 安装 Nginx Win10下Hyper-V设置网络连接 亲测Google开源JPEG图片压缩算法,可将JPEG文件缩小%35 android 术语 一些比较好用的网站整站下载工具 ASP.NET Page Life Cycle SQL跨数据库读取数据的方法 .net 注册和删除Windows服务 IIS7 下部署 MVC的注意事项 下载的四种方法 生成网站页面的截图 windows 下andriod 开发环境的搭建 无法上网,无线网络总是受限制或无连接 bcp命令详解-转载 searcherinder.exe .net 生成静态页
获取网页URL地址及参数等的两种方法(js和C#)
微雨杏花村 · 2011-04-29 · via 博客园 - 微雨杏花村

一 js

先看一个示例

用javascript获取url网址信息

<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>

执行 用javascript获取url网址信息 代码效果如下

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:

详细介绍 window.location方法获取URL

统一资源定位符 (Uniform Resource Locator, URL) 完整的URL由这几个部分构成:

scheme://host:port/path?query#fragment

scheme:通信协议

常用的http,ftp,maito等

host:主机

服务器(计算机)域名系统 (DNS) 主机名或 IP 地址。

port:端口号

整数,可选,省略时使用方案的默认端口,如http的默认端口为80。

path:路径

由零或多个”/”符号隔开的字符串,一般用来表示主机上的一个目录或文件地址。

query:查询

可选,用于给动态网页(如使用CGI、ISAPI、PHP/JSP/ASP/ASP.NET等技术制作的网页)传递参数,可有多个参数,用”&”符号隔开,每个参数的名和值用”=”符号隔开。

fragment:信息片断

字符串,用于指定网络资源中的片断。例如一个网页中有多个名词解释,可使用fragment直接定位到某一名词解释。(也称为锚点.)

示例: 

1, window.location.href

整个URl字符串(在浏览器中就是完整的地址栏)

返回值:http://www.2astudio.com:80/view.asp?id=209#cmt1323

2,window.location.protocol

URL 的协议部分

返回值:http:

3,window.location.host

URL 的主机部分,

返回值:www.2astudio.com

4,window.location.port

URL 的端口部分。如果采用默认的80端口(update:即使添加了:80),那么返回值并不是默认的80而是空字符。

本例返回值:空

5,window.location.pathname

URL 的路径部分(就是文件地址)

返回值:/view.asp

6,window.location.search

查询(参数)部分。除了给动态语言赋值以外,我们同样可以给静态页面,并使用javascript来获得相信应的参数值

返回值:?id=209

7,window.location.hash

锚点

返回值:#cmt1323

二 C#

底下这张表就是各种跟 Browser Request 的网址相关的属性与用法:

网址: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