mpen
mpen

Reputation: 282865

IIS/HttpHandler: Get relative absolute path?

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). How can I do that? Is there a way to get the "WebApplication6" bit so I know what to trim off? (inside IHttpHandler.ProcessRequest).

Upvotes: 4

Views: 9445

Answers (2)

VinayC
VinayC

Reputation: 49185

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

Upvotes: 4

tshao
tshao

Reputation: 1127

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

Upvotes: 0

Related Questions