开发者

IIS/HttpHandler: Get relative absolute path?

开发者 https://www.devze.com 2023-01-30 05:37 出处:网络
I\'ve got a site setup in IIS to run at http://localhost/WebApplication6. In my web application I have a handler (implements IHttpHandler). When I print context.Request.Url.AbsolutePath, I get /WebApp

I've got a site setup in IIS to run at http://localhost/WebApplication6. In my web application I have a handler (implements IHttpHandler). When I print context.Request.Url.AbsolutePath, I get /WebApplication6/whaetever. I want to trim off /WebApplication6 (the local site name). Ho开发者_开发技巧w can I do that? Is there a way to get the "WebApplication6" bit so I know what to trim off? (inside IHttpHandler.ProcessRequest).


Your best bet would be HttpRequest.AppRelativeCurrentExecutionFilePath - it provides path relative to your web application root directory. However, it will be in form of "~/whatever" where ~/ indicates app relative path. If your requirement is to get /whatever then you can strip off ~ using string functions.

BTW, here's good article that will help you make sense of all paths: http://www.west-wind.com/weblog/posts/132081.aspx


VirtualPathUtility.GetDirectory(context.Request.Url.AbsolutePath)
0

精彩评论

暂无评论...
验证码 换一张
取 消