Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有人可以解释一下 Server.MapPath 和 Request.MapPath 之间的区别以及两者的使用场景吗?
自 2.0 版以来,ASP.NET 至少提供了三种不同的公共 MapPath 方法:
在内部,HttpServerUtility.MapPath调用HttpRequest.MapPath.
HttpServerUtility.MapPath
HttpRequest.MapPath
HostingEnvironment.MapPath是一个静态方法,ArgumentNullException如果参数为 null 或空,则抛出一个,ArgumentException如果参数是相对路径,则抛出一个。
HostingEnvironment.MapPath
ArgumentNullException
ArgumentException
HttpRequest.MapPath不是静态方法,不会抛出上面提到的异常。