登录ASP.NET MVC和放原始的HTTP请求/响应; IIS7 [英] Logging raw HTTP request/response in ASP.NET MVC & IIS7

查看:182
本文介绍了登录ASP.NET MVC和放原始的HTTP请求/响应; IIS7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个Web服务(使用ASP.NET MVC)和支持的目的,我们希望能够在尽可能接近请求和响应记录到原始,上了线的格式(即包括HTTP方法,路径,所有标头和身体)到数据库中。

I'm writing a web service (using ASP.NET MVC) and for support purposes we'd like to be able to log the requests and response in as close as possible to the raw, on-the-wire format (i.e including HTTP method, path, all headers, and the body) into a database.

什么我不知道的是如何得到这个数据在最不'错位'的方式举行。我可以重新构成什么,我相信请求看起来像通过检查的Htt prequest 对象的所有属性,并从中构建一个字符串(同样为响应),但我很想得到的线路上发送的请求/响应数据的保持。

What I'm not sure of is how to get hold of this data in the least 'mangled' way. I can re-constitute what I believe the request looks like by inspecting all the properties of the HttpRequest object and building a string from them (and similarly for the response) but I'd really like to get hold of the actual request/response data that's sent on the wire.

我很高兴能使用任何的拦截机制,如过滤器,模块等,并且该解决方案可以具体到IIS7。不过,我想preFER以保持其管理$ C $只有c。

I'm happy to use any interception mechanism such as filters, modules, etc. and the solution can be specific to IIS7. However, I'd prefer to keep it in managed code only.

任何建议?

编辑:我注意到,的Htt prequest 有一个<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.htt$p$pquest.saveas.aspx\"><$c$c>SaveAs方法,可以保存请求到磁盘但这种重建使用无法公开访问(相当为什么不允许保存到用户提供的流,我不知道)内部helper方法负载从内部状态的要求。因此它开始像我必须尽我所能,从重建对象的请求/响应文本......呻吟声。

I note that HttpRequest has a SaveAs method which can save the request to disk but this reconstructs the request from the internal state using a load of internal helper methods that cannot be accessed publicly (quite why this doesn't allow saving to a user-provided stream I don't know). So it's starting to look like I'll have to do my best to reconstruct the request/response text from the objects... groan.

编辑2:请注意,我说的包括方法,路径,页眉等。目前唯一的反应看,不包括本体内流全的请求信息。

Edit 2: Please note that I said the whole request including method, path, headers etc. The current responses only look at the body streams which does not include this information.

修改3:难道没人看的问题在这里?五答案为止,但没有一甚至暗示的方式来得到整个原料上了线的要求。是的,我知道我可以从请求对象捕获输出流和标题和URL和所有的东西。我已经说过,在这个问题,请参见:

Edit 3: Does nobody read questions around here? Five answers so far and yet not one even hints at a way to get the whole raw on-the-wire request. Yes, I know I can capture the output streams and the headers and the URL and all that stuff from the request object. I already said that in the question, see:

我可以重新构成什么,我相信请求看起来像通过检查的Htt prequest对象的所有属性,并从中构建一个字符串(同样的响应),但我很想弄个那对电线发送的请求/响应数据。

I can re-constitute what I believe the request looks like by inspecting all the properties of the HttpRequest object and building a string from them (and similarly for the response) but I'd really like to get hold of the actual request/response data that's sent on the wire.

如果您知道的完整的,这将是非常有用的原始数据(包括标题,URL,HTTP方法等),根本无法再取回就知道了。同样,如果你知道如何得到这一切在原始格式(是的,我的意思是还包括标题,URL,HTTP方法等),而无需重建它,这是我问,那么这将是非常有用的。但是,告诉我,我可以从的Htt prequest / 的Htt presponse 对象重建它不有用。我知道。我已经说过了。

If you know the complete raw data (including headers, url, http method, etc.) simply cannot be retrieved then that would be useful to know. Similarly if you know how to get it all in the raw format (yes, I still mean including headers, url, http method, etc.) without having to reconstruct it, which is what I asked, then that would be very useful. But telling me that I can reconstruct it from the HttpRequest/HttpResponse objects is not useful. I know that. I already said it.


请注意:任何人都开始前说这是一个坏主意,或将限制可扩展性等方面,我们也将实现节流,连续交付,并在分布式环境中抗重播机制,所以数据库日志总是需要。我不是在寻找这是否是一个好主意的讨论,我正在寻找它可以怎么做。

推荐答案

确定,所以它看起来像答案是不,你不能得到的原始数据,你必须从重建的属性请求/响应解析的对象。噢,我已经做了重建的事情。

OK, so it looks like the answer is "no you can't get the raw data, you have to reconstruct the request/response from the properties of the parsed objects". Oh well, I've done the reconstruction thing.

这篇关于登录ASP.NET MVC和放原始的HTTP请求/响应; IIS7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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