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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Palo Alto Networks Blog
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
有赞技术团队
有赞技术团队
The GitHub Blog
The GitHub Blog
C
Cisco Blogs
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
Simon Willison's Weblog
Simon Willison's Weblog
T
Tenable Blog
Know Your Adversary
Know Your Adversary
Spread Privacy
Spread Privacy
WordPress大学
WordPress大学
月光博客
月光博客
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threat Research - Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
I
InfoQ
D
Darknet – Hacking Tools, Hacker News & Cyber Security
W
WeLiveSecurity
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
U
Unit 42
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
T
The Exploit Database - CXSecurity.com
I
Intezer
GbyAI
GbyAI
Jina AI
Jina AI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Google Online Security Blog
Google Online Security Blog
Engineering at Meta
Engineering at Meta
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
小众软件
小众软件
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
Project Zero
Project Zero

博客园 - 曲达子

Oralce sys system密码找回 oracle服务丢失的解决办法 JS 实现table 分页 xmlHttp 中乱码处理 C# windows 服务(转) 在oc4j中安装、配置MapViewer 关于PostBack(转) 自定义控件属性的一些特性 oracle 游标使用 (转)实用JaveScript 用.NET 2.0压缩/解压封装的类 (转) ASP.NET 项目中用到的广告效果(转) js 在杂烩 在NHibernate中使用Oracle的sequence主键 window对象详解 asp.net 获取服务器信息 刷新父窗口 js中一些鼠标事件 常见问题与错误小总结
路径问题
曲达子 · 2008-08-04 · via 博客园 - 曲达子

原文出处:http://www.wangchao.net.cn/bbsdetail_544275.html
很经常使用到的一个功能,但在在网上却一直没有找到相关的解决方法,今天借着项目应用到的机会写了两个将绝对路径转换为虚拟路径封装好的方法将Web站点下的绝对路径转换为相对于指定页面的虚拟路径 /**//// <summary> /// 将Web站点下的绝对路径转换为相对于指定页面的虚拟路径 /// </summary> /// <param name="page">当前页面指针,一般为this</param> /// <param name="specifiedPath">绝对路径</param> /// <returns>虚拟路径, 型如: http://www.cnblogs.com/</returns> public static string ConvertSpecifiedPathToRelativePathForPage(Page page, string specifiedPath) { // 根目录虚拟路径 string virtualPath = page.Request.ApplicationPath; // 根目录绝对路径 string pathRooted = HostingEnvironment.MapPath(virtualPath); // 页面虚拟路径 string pageVirtualPath = page.Request.Path; if (!Path.IsPathRooted(specifiedPath) || specifiedPath.IndexOf(pathRooted) == -1) { throw new Exception(string.Format("\"{0}\"是虚拟路径而不是绝对路径!", specifiedPath)); } // 转换成相对路径 //(测试发现,pathRooted 在 VS2005 自带的服务器跟在IIS下根目录或者虚拟目录运行似乎不一样, // 有此地方后面会加"\", 有些则不会, 为保险起见判断一下) if (pathRooted.Substring(pathRooted.Length - 1, 1) == "\\") { specifiedPath = specifiedPath.Replace(pathRooted, "/"); } else { specifiedPath = specifiedPath.Replace(pathRooted, ""); } string relativePath = specifiedPath.Replace("\\", "/"); string[] pageNodes = pageVirtualPath.Split('/'); // 减去最后一个页面和前面一个 "" 值 int pageNodesCount = pageNodes.Length - 2; for (int i = 0; i < pageNodesCount; i  ) { relativePath = "/.."   relativePath; } if (pageNodesCount > 0) { // 如果存在 ".." , 则把最前面的 "/" 去掉 relativePath = relativePath.Substring(1, relativePath.Length - 1); } return relativePath; } 第二个方法显然是从第一个方法中的前部分抽取出来的,所以懒得去添加相关注释 :P 将Web站点下的绝对路径转换为虚拟路径 /**//// <summary> /// 将Web站点下的绝对路径转换为虚拟路径 /// 注:非Web站点下的则不转换 /// </summary> /// <param name="page">当前页面指针,一般为this</param> /// <param name="specifiedPath">绝对路径</param> /// <returns>虚拟路径, 型如: ~/</returns> public static string ConvertSpecifiedPathToRelativePath(Page page, string specifiedPath) { string virtualPath = page.Request.ApplicationPath; string pathRooted = HostingEnvironment.MapPath(virtualPath); if (!Path.IsPathRooted(specifiedPath) || specifiedPath.IndexOf(pathRooted) == -1) { return specifiedPath; } if (pathRooted.Substring(pathRooted.Length - 1, 1) == "\\") { specifiedPath = specifiedPath.Replace(pathRooted, "~/"); } else { specifiedPath = specifiedPath.Replace(pathRooted, "~"); } string relativePath = specifiedPath.Replace("\\", "/"); return relativePath; } 将虚拟路径转绝对路就没什么好说的了, HttpRequest.MapPath 方法专门干这事