All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
visual c++中树视图控件(Tree Control)
MySQL,5.0,数据库的新特性的存储过程_php资料_编程技术
详细介绍PHP动态网页技术中SESSION的应用_php资料_编程技术
Visual C++ 6.0中的应用程序向导
详细讲解PHP中缓存技术的应用_[PHP教程]
php常用数据库备份类_[PHP教程]
asp.net2.0推荐一个功能强大的图片选择控件_[Asp.Net教程]
十六 有害的标签 Bad Tags_[Html教程]
DataSet数据导入Excel的c#代码_[Asp.Net教程]
ASP.NET开发系列之在用户控件中添加事件_[Asp.Net教程]
Reading number is top 10 pictures
Household design of gorgeous series
刘亦菲写真集1
这张图有两句话,你看出来了吗?
China's ambassador to Libya embassy was shock, and the glass is broken in
明星与豪宅
Send some Valentine's day cartoon
Beauty is thus produced
Sora aoi on twitter3
Breasts woman big set 1
乳娘帕梅拉安德森3
Download software ranking
Be there or be square
实战黑客不求人
linux安装大全
Tram sex maniac 2 (H) rar bag8
Boxer's Top ten classic battle4
matrix2
网络管理员第三版
传奇私服架设教程
Unix video tutorial18
Tram sex maniac 2 (H) rar bag5
归海一刀 published in(发表于) 2014/1/30 1:23:44 Edit(编辑)
ASP.NET编程取得网站绝对路径5方法_[Asp.Net教程]

ASP.NET编程取得网站绝对路径5方法_[Asp.Net教程]

ASP.NET编程取得网站绝对路径5方法_[Asp.Net教程]
下面就是几种获取绝对路径的几种方法。

VirtualPathUtility.ToAbsolute( " ~/ " )
HttpRuntime.AppDomainAppVirtualPath
Request.ApplicationPath
Page.ResolveUrl( " ~ " )

以上代码生成的结果如下:
当以网站的方式访问时,结果如下:

VirtualPathUtility.ToAbsolute("~/") = /
HttpRuntime.AppDomainAppVirtualPath = /
Request.ApplicationPath = /
Page.ResolveUrl("~") = /

当以虚拟目录(http://localhost:806/web2/url.aspx)访问时,结果如下:

VirtualPathUtility.ToAbsolute("~/") = /web2/
HttpRuntime.AppDomainAppVirtualPath = /web2
Request.ApplicationPath = /web2
Page.ResolveUrl("~") = /web2/

采用第二种和第三种方法,还需要做一下处理,因为网站访问时是以/结尾,而以虚拟目录访问时则是没有/的,进行还得进行一次判断,稍微麻烦一点。
但是,这些方法在页面中使用是没有任何问题的,但是如果在 Global 的 Application_Start 事件里需要得到网站的绝对路径,则需要使用前面2种方法,如果使用第三种方法,则会报告如下的错误:
Request is not available in this context
所以,只能采取头2种方法。例如

void Application_Start( object sender, EventArgs e)
{
System.IO.StreamWriter s = new System.IO.StreamWriter(HttpRuntime.AppDomainAppPath + " log.txt " );
s.WriteLine(VirtualPathUtility.ToAbsolute( " ~/ " ));
s.WriteLine(HttpRuntime.AppDomainAppVirtualPath);
s.Close();
}


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.