How can I create an http handler to redirect all t

2019-07-30 05:48发布

问题:

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.