如何读取ASP.NET发送给客户端的所有HTTP标头? [英] How to read all HTTP-Headers that ASP.NET sends to the client?

查看:54
本文介绍了如何读取ASP.NET发送给客户端的所有HTTP标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于日志记录的目的,我想阅读 all 的HTTP标头,这些标头发送到应用程序中任意位置的客户端,以便将其记录到数据库中.但是, 位置标头始终会丢失 .也许还有更多我永远不会知道的失踪.如何获得所有标题?

For logging purposes i want to read all HTTP-Headers which are sent to the client anywhere in my application in order to log them to the database. However the Location-header is always missing on redirects. maybe there are even more missing that i will never know about. How can i get all headers?

推荐答案

访问HttpResponse对象的Headers集合存在很多问题.基本上,您需要以集成管道模式"运行IIS7.如果可以这样做,您可以在适当的时间简单地查看Response.Headers集合.在Global.asax文件中尝试以下操作:

There are a lot of issues surrounding accessing the Headers collection of an HttpResponse object. Basically you need to be running IIS7 in "integrated pipeline mode". If you can do this, you could simply take a look at the Response.Headers collection at the appropriate time. Try something like this in your Global.asax file:

 protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
    {
        foreach (var header in Response.Headers)
        {
            // Log to database
            insertIntoDatabase(header.ToString())
        }
    }

如果您没有运行IIS7,那么您可能不适合使用简单的代码解决方案.

If you're not running IIS7... then you might be out of luck for an easy code solution.

这篇关于如何读取ASP.NET发送给客户端的所有HTTP标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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