简体   繁体   English

在背后的aspx页面代码上读取传入的标题

[英]Reading incoming Headers on aspx page code behind

There is a process that will send an http post request to a specific url, and from there I need to read information stored in the request headers (specifically X-RIM-Push-ID and X-RIM-Push-Status) 有一个过程会将http发布请求发送到特定的url,从那里我需要读取存储在请求标头中的信息(特别是X-RIM-Push-ID和X-RIM-Push-Status)

Is it possible to read the headers using IIS 6? 是否可以使用IIS 6读取标题?

I'm planning on using: 我打算使用:

var id = Response.Headers["X-RIM-Push-ID"]; var id = Response.Headers [“ X-RIM-Push-ID”];

We can use reflection and can be read the response headers 我们可以使用反射并可以读取响应头

        try
        {
            var header = HttpContext.Current.Response;

            header.AppendHeader("test0", "1");
            header.AppendHeader("test1", "2");
            header.AppendHeader("test2", "2");
            header.AppendHeader("test3", "3");
            header.AppendHeader("test4", "4");


            MethodInfo dynMethod = header.GetType().GetMethod("GenerateResponseHeaders", BindingFlags.NonPublic | BindingFlags.Instance);
            var result =  dynMethod.Invoke(header, new object[] { false });
        }
        catch (HttpRequestValidationException ex)
        {
            string str = ex.Message;
        }

If you are looking for request headers in ASP.NET: 如果要在ASP.NET中查找请求标头:

var id = Request.Headers["X-RIM-Push-ID"];

Is it possible to read the headers using IIS 6? 是否可以使用IIS 6读取标题?

Hmm, usually it's your application that should read headers, not sure what you mean here. 嗯,通常应该是您的应用程序读取标头,不确定此处的含义。

I believe you need IIS7 running in pipeline mode. 我相信您需要以管道模式运行的IIS7。 See this msdn article. 请参阅此msdn文章。 See this msdn article 请参阅此msdn文章

Enjoy! 请享用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM