IIS / HttpHandler: Get relative absolute path?

I have a site setup in IIS to work in 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 crop /WebApplication6(local site name). How can i do this? Is there a way to get the "WebApplication6" bit so that I know what to trim? (inside IHttpHandler.ProcessRequest ).

+3
source share
2 answers

HttpRequest.AppRelativeCurrentExecutionFilePath would be best - it provides a path relative to the root directory of your web application. However, it will be in the form of " ~/whatever", where it ~/indicates the relative path of the application. If you need to get /whatever, you can disable ~ using string functions.

By the way, here is a good article to help you understand all the ways: http://www.west-wind.com/weblog/posts/132081.aspx

+4
source
VirtualPathUtility.GetDirectory(context.Request.Url.AbsolutePath)
0
source

Source: https://habr.com/ru/post/1780168/


All Articles