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

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
罗磊的独立博客
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
The Register - Security
The Register - Security
J
Java Code Geeks
V2EX - 技术
V2EX - 技术
Vercel News
Vercel News
N
News and Events Feed by Topic
腾讯CDC
P
Proofpoint News Feed
N
News | PayPal Newsroom
www.infosecurity-magazine.com
www.infosecurity-magazine.com
爱范儿
爱范儿
O
OpenAI News
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
D
Docker
Y
Y Combinator Blog
博客园 - 聂微东
G
Google Developers Blog
S
Security @ Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
阮一峰的网络日志
阮一峰的网络日志
C
CXSECURITY Database RSS Feed - CXSecurity.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
CERT Recently Published Vulnerability Notes
I
Intezer
G
GRAHAM CLULEY
有赞技术团队
有赞技术团队
Attack and Defense Labs
Attack and Defense Labs
V
Visual Studio Blog
博客园 - Franky
博客园 - 三生石上(FineUI控件)
W
WeLiveSecurity
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hugging Face - Blog
Hugging Face - Blog
Scott Helme
Scott Helme
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LINUX DO - 最新话题
C
Cybersecurity and Infrastructure Security Agency CISA

博客园 - 落木

PowerDesigner中NAME和COMMENT的互相转换,需要执行语句 Control的Invoke和BeginInvoke 扩大范围的多条件查询 用.net的GetCallbackEventReference函数来实现dropDownList联动的ajax效果 处理SQLSERVER死锁(转载) 调用DirectX进行简单的多媒体编程系列(四) 调用DirectX进行简单的多媒体编程系列(三) 调用DirectX进行简单的多媒体编程系列(二) 调用DirectX进行简单的多媒体编程系列(一) 数据库分页算法 mysql想说爱你不容易啊,从mssql迁移到mysql时,几乎所有的存储过程都得改,语法相差很大,累人!! 自己写的sqlserver和mysql的行转列通用存储过程 MSSQL优化文章 C#中编写sqlserver中自定义函数,实现复杂报表 Ajax使用Post方式提交到.aspx页面交互的例子 核单台帐表(存储过程) 清欠率(存储过程) ExtJS中的面向对象设计,组件化编程思想 - 落木 - 博客园 ExtJS中如何扩展自定义的类
获取网站根目录的urli源代码 - 落木 - 博客园
落木 · 2010-12-08 · via 博客园 - 落木

    public static string GetRootURI()
    {
        
string AppPath = "";
        HttpContext HttpCurrent 
= HttpContext.Current;
        HttpRequest Req;
        
if (HttpCurrent != null)
        {
            Req 
= HttpCurrent.Request;string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);
            
if (Req.ApplicationPath == null || Req.ApplicationPath == "/")
                
//直接安装在   Web   站点   
                AppPath = UrlAuthority;
            
else
                
//安装在虚拟子目录下   
                AppPath = UrlAuthority + Req.ApplicationPath;
        }
        
return AppPath;
    }

在ASP.NET中可以对Reqeust对象中获取web应用程序或网站的虚拟根目录,物理文件路径等信息,可以解析出URI的相关目录.1:测试代码

测试URL :http:

//localhost:8080/Default2.aspx

      Response.Write(
"Request.RawUrl:" + " 获取客户端请求的 URL 信息(不包括主机和端口)------> " + Request.RawUrl + "<br />");
        Response.Write(
"Request.ApplicationPath :" + "获取服务器上 ASP.NET 应用程序的虚拟路径。------> " + Request.ApplicationPath + "<br />");
        Response.Write(
"Request.CurrentExecutionFilePath :" + " 获取当前请求的虚拟路径。 ------> " + Request.CurrentExecutionFilePath + "<br />");
        Response.Write(
"Request.Path :" + " 获取当前请求的虚拟路径。 ------> " + Request.Path + "<br />");
        Response.Write(
"Request.PathInfo : " + " 取具有 URL 扩展名的资源的附加路径信息 ------>" + Request.PathInfo + "<br />");
        Response.Write(
"Request.PhysicalPath: " + " 获取与请求的 URL 相对应的物理文件系统路径。 ------>" + Request.PhysicalPath + "<br />");
        Response.Write(
"Request.Url.LocalPath : " + "    ------>" + Request.Url.LocalPath + "<br />");
        Response.Write(
"Request.Url.AbsoluteUri: " + " ------>" + Request.Url.AbsoluteUri + "<br />");
        Response.Write(
"Request.Url.AbsolutePath : " + " ---------------------- ------>" + Request.Url.AbsolutePath + "<br />");2:测试结果

Request.RawUrl: 获取客户端请求的 URL 信息(不包括主机和端口)

------> /Default2.aspx
Request.ApplicationPath :获取服务器上 ASP.NET 应用程序的虚拟路径。
------> /
Request.CurrentExecutionFilePath : 获取当前请求的虚拟路径。 
------> /Default2.aspx
Request.Path : 获取当前请求的虚拟路径。 
------> /Default2.aspx
Request.PathInfo : 取具有 URL 扩展名的资源的附加路径信息 
------>
Request.PhysicalPath: 获取与请求的 URL 相对应的物理文件系统路径。 
------>E:\temp\Default2.aspx
Request.Url.LocalPath : 
------>/Default2.aspx
Request.Url.AbsoluteUri: 
------>http://localhost:8080/Default2.aspx
Request.Url.AbsolutePath : ---------------------- ------>/Default2.aspx


 查下使用Server.MapPath进行虚拟目录映射的问题,我进行了一把试验:

试验条件:w1网站物理路径为F:\temp\代码示例\WebSite1,默认网站的物理路径C:\inetpub\wwwroot,对于w1网站的某网页调用 Server.MapPath方法。

 试验结果:

  Server.MapPath("")  w1返回F:\temp\代码示例\WebSite1 ,即w1网站物理路径2   Server.MapPath("/") w1返回C:\inetpub\wwwroot,即默认网站物理路径3  Server.MapPath("Bin") w1返回F:\temp\代码示例\WebSite1\Bin

4  Server.MapPath("/Bin") w1返回C:\inetpub\wwwroot\Bin返回的是默认网站物理路径+/Bin 

总结下:参数是以斜杠开头( / \ )或者../ ..\ 等开头,那么首先取默认网站的物理路径,即C:\Inetpub\wwwroot,再加上传入的传入的路径参数;如果不是以这类符号开头的话,就是取当前网站的物理路径,即F:\temp\代码示例\WebSite1 ,再加上传入的路径参数。

 注意:Server.MapPath不保证返回的物理路径是有效路径。

 
试验了几把发现都还正确,不知道这种考虑方式是否正确,