IHttpModule 插入入站过滤器破坏 WCF,如何调整内容长度?
在 ASP.NET 4.0 中,我有一个在 HttpRequest.Filter
上应用过滤器的 IHttpModule
。结果,内容流长度发生了变化,并且由于正文长度和 HTTP 标头之间不匹配,它破坏了 WCF,现在返回 400 bad request
。
知道如何解决 WCF 的这种行为吗?
In ASP.NET 4.0, I have an IHttpModule
that apply a filter on HttpRequest.Filter
. As the result, the content stream length is changed, and it breaks WCF with now returns 400 bad request
because of the mismatch between the body length and the HTTP headers.
Any idea how to solve this behavior of WCF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
真正需要的只是删除错误的 Content-Length 标头,但 IIS6 中不允许这样做。不确定集成管道模式下的 IIS7。对于使用您的过滤器的任何响应,请将此更新应用于标头。这个想法是获取内容类型(这样你就不会破坏任何非文本响应)和任何存在的cookie(这样你就不会破坏身份验证),清除所有标头(以清除内容长度),然后设置再次输入内容类型和 cookie。我们在 HttpApplication.ReleaseRequestState 事件中应用过滤器,然后进行以下处理。 YMMV。
All that is really needed is to delete the erroneous Content-Length header, but that isn't allowed in IIS6. Not sure about IIS7 in integrated pipeline mode. For any response that uses your filter, apply this update to the headers. The idea is to get the content type (so you don't break any non-text responses) and any cookies present (so you don't break authentication), clear all the headers (to clear the Content-Length), then set the content type and cookies again. We apply our filter in the HttpApplication.ReleaseRequestState event and then do the following processing. YMMV.
猜猜这是您的问题:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/fa132e84-3e3f-4152-9ffa-3f860a266e9f/
Guess this is for your question:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/fa132e84-3e3f-4152-9ffa-3f860a266e9f/