一些背景信息:我已经使用基于Mike Volodarsky的this博客条目的.NET Framework为IIS7创建了自定义处理程序和自定义模块。
到目前为止,处理程序&模块,但这是我的问题/场景。
如果处理程序识别出给定URL上的请求,我需要读取cookie,获取其信息并将这些数据添加到传入请求的标头中。
到目前为止,我的编码是'IHttpHandler'成员:
public void ProcessRequest(HttpContext context)
{
var response = context.Response;
//var request = context.Request;
var cookieInformation = GetSomeInformationFromCookie();
if (!string.IsNullOrEmpty(cookieInformation))
{
var nameValueCollection = new NameValueCollection
{{"CustomAspNetHeader", cookieInformation}};
response.Headers.Add(nameValueCollection);
}
// I would like to proceed the current request
// just with the updated header-information.
}
有没有办法更新传入请求的标头信息?
让我们成像我们有一个名为' MyPage.aspx '的页面。在 PageLoad-Event 中,我们写了类似的内容:
foreach (var header in HttpContext.Current.Request.Headers)
{
var value = HttpContext.Current.Request.Headers[header.ToString()];
var s = string.Format("Header: <strong>{0}</strong>, Value: <strong>{1}</strong><br />", header, value);
Response.Write(s);
}
基本上我从foreach循环中获得以下信息:
现在,我们启用处理程序以在IIS7-Manager中侦听具有 .aspx 扩展名的文件。 如果我们第二次运行' MyPage.aspx ',则会触发 PageLoad-Event 并显示所有标题信息......这就是我的问题。我看不到任何东西,因为处理程序正在处理'MyPage.aspx'的传入请求,并且从未到达/触发PageLoad-Event。
也许有另一种技术可以更新传入请求的标头信息(在.NET中)。
非常感谢任何帮助。
答案 0 :(得分:0)
从您编写的Http处理程序中获取代码,并在global.asax中运行它。
这样的事情:
protected void Application_BeginRequest()
{
// Manipulate the headers as you see fit.
}