How can I get the tilde (~) operator to work when rewriting URLs in an HttpModule?

强颜欢笑 提交于 2019-12-12 15:27:39

问题


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

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:

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?


回答1:


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.



来源:https://stackoverflow.com/questions/18005227/how-can-i-get-the-tilde-operator-to-work-when-rewriting-urls-in-an-httpmodul

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!