是否可以在IIS下拦截Web请求? [英] Is it possible to intercept the web request under IIS?

查看:81
本文介绍了是否可以在IIS下拦截Web请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经使用IIS在端口 80 下部署了一些Web服务,例如:

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个服务

一次添加统计信息和身份验证登录.

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创建一个单独的应用程序.

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?

顺便说一句,已部署服务的URL无法更改.

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

有什么建议吗?

推荐答案

我认为您最好的选择是创建一个HTTP模块,然后将该模块添加到您的应用中,然后该应用将能够拦截进入其托管的每个请求应用程序.

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.

在官方页面上

HTTP模块是一个程序集,在对以下内容的每个请求中都会调用该程序集:你的申请.HTTP模块被称为ASP.NET的一部分请求管道并可以访问整个生命周期事件要求.因此,HTTP模块为您提供了检查的机会传入请求并根据请求采取措施.他们也给您将有机会检查出站响应并进行修改.

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

创建简单HTTP模块的演练 http://msdn.microsoft.com/zh-us/library/ms227673(v = vs.100).aspx

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

作为拦截呼叫的同一主题的一部分,我强烈建议您阅读下面的文章,该文章描述了HTTP处理程序和HTTP处理器的各个方面.HTTP模块. http://msdn.microsoft.com/zh-我们/library/bb398986(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

更新根据您的评论,您将需要创建一个ISAPI筛选器,该筛选器类似于HTTP模块描述的技术,但是可以在IIS级别而不是应用程序级别.可以在此处找到有关此方法的更多信息: http://msdn.microsoft.com/en-us/library/ms524610(v=vs.90).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

但是请注意,您不能使用现有技能来编写此类过滤器,因为它仅支持使用C/C ++进行编程.

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

希望这会有所帮助:)

这篇关于是否可以在IIS下拦截Web请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆