Question

I am using the rather excellent IIS7 Rewrite module (V2), and want to create a custom RewriteProvider that rewrites differently depeneding on whether the physical file exists.

I have successfully created a provider, as in this tutorial: http://learn.iis.net/page.aspx/804/developing-a-custom-rewrite-provider-for-url-rewrite-module/

However, really need to be able to map the url to a physical path - I would normally do this via HttpContext.Current.Server.MapPath() or HostingEnvironment.MapPath(), but it looks like the HttpContext has not been initialised (at least within the current App Domain - since the ReWrite module is native code, I'm having difficulty working out where I can get this information).

I don't really want to have to resort to creating my own rewrite module to get around this problem - anyone have any clues for me?

Thanks! Mark.

Was it helpful?

Solution

You will not be able to get to it using those APIs since the code runs in a different AppDomain than the one ASP.NET is using.

The only way I can think to make this work is to pass the right Server Variable that includes the physical path to your extension and do a Path.Combine() yourself.

So assuming you have an extension called YourProvider that you are calling somehow like this: {YourProvder:{URL}}

You can do: {YourProvder:{APPL_PHYSICAL_PATH}|{URL}}

You can now get the physical path and the URL separated by a pipe | , make sure to pass the Physical Path first since the URL is in the control of external users you do not want them to trick you into getting a different physical path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top