当前位置:首页>>开发编程>>VS.NET>>新闻内容  
ASP.NET与Javascript中获取URL信息
作者: 发布时间:2007-11-24 16:13:05 | 【字体:
我们假设访问这个地址:http://localhost:1351/WebSite1/dir/Default.aspx/adsf?id=12#test  ,下面是各个方法的返回值。

ASP.NET

Request Property Result Remark
Request.ApplicationPath /WebSite1 相对于应用程序(而非虚拟目录)根目录的路径
Request.PhysicalApplicationPath C:\Documents and Settings\wstone.SPANSION\Desktop\WebSite1\ 应用程序根目录的物理路径
Request.PhysicalPath C:\Documents and Settings\wstone.SPANSION\Desktop\WebSite1\dir\Default.aspx 当前请求的物理路径
Request.PathInfo /adsf 附加的路径信息
Request.RawUrl /WebSite1/dir/Default.aspx/adsf?id=12 当前请求相对于应用程序根目录的路径
Request.Url http://localhost:1351/WebSite1/dir/Default.aspx/adsf?id=12 当前请求的完整路径(不包括#之后的)
Request.CurrentExecutionFilePath /WebSite1/dir/Default.aspx
Request.FilePath /WebSite1/dir/Default.aspx
Request.Path /WebSite1/dir/Default.aspx/adsf
Request.ServerVariables["SERVER_NAME"] localhost
Request.ServerVariables["SERVER_PORT"] 1351
Request.ServerVariables["SERVER_PORT_SECURE"] 0
Server.MapPath("~") C:\Documents and Settings\wstone.SPANSION\Desktop\WebSite1
Server.MapPath("~/") C:\Documents and Settings\wstone.SPANSION\Desktop\WebSite1\
Server.MapPath("~/1.jpg") C:\Documents and Settings\wstone.SPANSION\Desktop\WebSite1\1.jpg
#test ASP.NET中不能得到#之后的test,因为#不回发页面

PS:在VS2005中打开WebSite1网站,在浏览器中查看,此时WebSite1为虚拟目录。

Javascript

Location Property Result
location.hash #test
location.host localhost:1351
location.hostname localhost
location.href http://localhost:1351/WebSite1/dir/Default.aspx/adsf?id=12#test
location.pathname /WebSite1/dir/Default.aspx/adsf
location.port 1351
location.protocol http:
location.search ?id=12

文章来源:
·在ASP.NET中使用AJAX的简单方法
·ASP.NET后台代码实现XmlHttp跨域访问
·ASP.NET取得当前页面的完整URL
·如何在ASP.NET程序里面执行DOS命令
·IIS5IIS6IIS7的ASP.net请求处理过程比较
·ASP.NET备份SQL Server数据库的方法
·让网站图片“另存为”“无标题.bmp”的技巧
·ASP.NET GridView的分页功能
·ASP.NET实现字母+数字方式验证码
·ASP.NET采集系统万能正则表达式
 放生
 愚爱
 够爱
 触电
 白狐
 葬爱
 光荣
 画心
 火花
 稻香
 小酒窝
 下雨天
 右手边
 安静了
 魔杰座
 你不像她
 边做边爱
 擦肩而过
 我的答铃
 怀念过去
 等一分钟
 放手去爱
 冰河时代
 你的承诺
 自由飞翔
 原谅我一次
 吻的太逼真
 左眼皮跳跳
 做你的爱人
 一定要爱你
 飞向别人的床
 爱上别人的人
 感动天感动地
 心在跳情在烧
 玫瑰花的葬礼
 有没有人告诉你
 即使知道要见面
 爱上你是一个错
 最后一次的温柔
 爱上你是我的错
 怎么会狠心伤害我
 不是因为寂寞才想
 亲爱的那不是爱情
 难道爱一个人有错
 寂寞的时候说爱我