Is it possible to intercept the web request under IIS?

时光毁灭记忆、已成空白 提交于 2021-01-28 13:40:19

问题


We have deploy some web service under port 80 using IIS, like:

http://localhost/service1/
http://localhost/service2/
...

Now we want to do some statistics and authentication job for these services, now I have two ideas:

1 change each service

Add the statistics and authentication login one by one.

But I think this is not a good idea since we have so many application to be updated, and these codes are repeated seriously.

2 Create a separate application.

This application should can intercept each request of the services, and do the related job. And we can add other features for this application someday.

This is the flexible way I think. But I am not sure if this is possible?

BTW, the url of the deployed services can not be changed.

Any suggestion?


回答1:


I think your best pet is to create a HTTP Module, then add this module to your apps, which will then be able to intercept every request coming to it's hosting application.

From the official page

An HTTP module is an assembly that is called on every request made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life cycle events throughout the request. HTTP modules therefore give you the opportunity to examine incoming requests and take action based on the request. They also give you the opportunity to examine the outbound response and modify it.

more on this topic can be found via the following links:

http://msdn.microsoft.com/en-us/library/ms178468(v=vs.85).aspx

a walk through of creating a simple HTTP Module http://msdn.microsoft.com/en-us/library/ms227673(v=vs.100).aspx

as part of the same topic of intercepting calls, I hihgly recommend you to read the following article describing the various aspects of both HTTP Handlers & HTTP Modules. http://msdn.microsoft.com/en-us/library/bb398986(v=vs.100).aspx

Update as per your comment, you will need to create an ISAPI filter, which is similar to the descried technique of HTTP Module, but can be on the IIS level instead of the Application level. more can be found about this way here: http://msdn.microsoft.com/en-us/library/ms524610(v=vs.90).aspx

but note that you cannot use your existing skills to write such filter, as it only supports programming using C/C++.

Hope this helps :)



来源:https://stackoverflow.com/questions/22632214/is-it-possible-to-intercept-the-web-request-under-iis

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