How can I create an http handler to redirect all traffic to HTML pages?

て烟熏妆下的殇ゞ 提交于 2019-12-11 05:46:50

问题


Our company would like to redirect all calls to html files on our server to a separate page. The html pages are NOT in an asp.net application.

In order to do this, I've been writing and IIS Handler in asp.net.

1) Is this possible to add an IIS handler to redirect static content that isn't served by any asp.net engine, i.e. stand alone files on the server?

2) If it is possible, how do I do this? I created an http handler in a class library. In the app.config I added the handler to the and sections. I added the DLL to the GAC, I changed the html mapping to my custom IIS dll and nothing works. Is there a tutorial or explanation from A to B on how to do this?

Thanks.

E

p.s. I'm using IIS 7.5


回答1:


By default, IIS will handle requests with extensions. This means your custom HTTP handler isn't being called. If you want managed code to handle all requests then you'll need to set this configuration in Web.config:

<modules runAllManagedModulesForAllRequests="true" />

Then, it's a simple matter of registering your HTTP handler in Web.config, making sure it's the first handler to receive all requests.

Also, you may want to check into IIS URL rewriting as it may be a better-performance solution to this problem.



来源:https://stackoverflow.com/questions/9563818/how-can-i-create-an-http-handler-to-redirect-all-traffic-to-html-pages

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