日期:2014-05-17  浏览次数:20524 次

一般处理程序ashx能否获得完整的原始的请求头信息?
一般处理程序ashx能否获得完整的原始的请求头信息?

是原始的,尚未解析的请求头字符串信息!!!


C# code

using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.RegularExpressions;

namespace idCheck.net.genealogy
{
    /// <summary>
    /// getMessages 的摘要说明
    /// </summary>
    public class getMessages : IHttpHandler
    {

        personMessage pm = new personMessage();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string requestHeader = //  这里该如何写???用于获取原始的不是解析后的请求头字符串信息!!!
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}


------解决方案--------------------
举个例子:
C# code
var sb = new StringBuilder("<head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"><title>举例</title></head><html>");
sb.Append(Program.httpServer.Info);
if (context.Request.Headers.Count > 0)
{
    sb.Append("<hr />你的浏览器信息:<br />");
    for (var i = 0; i < context.Request.Headers.Count; i++)
    {
        var k = context.Request.Headers.GetKey(i);
        var x = context.Request.Headers.GetValues(i);
        sb.Append(HttpUtility.HtmlEncode(string.Format("{0}={1}", k, string.Join(",", x))) + "<br />");
    }
}
sb.Append("</html>");