Вопрос

I am using RewritePath() in an IHttpModule to "route" to sub-web applications, as in this IIS layout:

enter image description here

For example, when a request for /root/bleh comes in, an HTTP module in the root application rewrites the path to /root/obw in hopes that the obw application will take over.

This mostly works, except that the tilde (~) does not resolve properly:

enter image description here

The tilde operator resolves to the root web app after the rewrite, not the obw web app. This seems to be the sort of thing the rebaseClientPath argument to RewritePath() is meant to account for, but changing that argument doesn't appear to make any difference.

How can I get the tilde (~) operator to properly resolve when rewriting URLs?

Это было полезно?

Решение

This doesn't work because RewritePath is not designed to send a request to a different application. You say that it 'mostly works', but in reality it is not doing what you think, and is handling the rewritten request in the same application. This is why the ~ is not resolving to the sub app.

There are lots of things that won't work either. e.g.

  • if you have a global.asax under your obw folder, it will be ignored
  • you won't be able to load assemblies that come from obw/bin

In other words, in the context of RewritePath it's just treating obw as a plain subfolder and not as anything special.

As an alternative, you could consider using the IIS URL Rewriter module, which won't have this issue.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top