2012-05-25 91 views
0

我正在寫http處理程序。我只是想添加一些http標題,之後,我希望行爲與以前一樣。有沒有辦法轉發Http處理程序中的請求

我喜歡處理以下

public void ProcessRequest(HttpContext context) 
{ 
    HttpResponse Response = context.Response;  

    Response.Headers.Add("item", "data"); 
} 

但它不工作和以前一樣。我在這裏錯過了什麼?

+0

我認爲你需要擴展你的問題 - 你爲什麼需要一個處理程序來添加頭文件?有多種/更簡單的方法可以做到這一點,取決於你的預期結果是... – EdSF

+0

@EdSF,請讓我以其他方式。我不限制處理程序。 –

回答

0

如果您使用的是ASP.NET MVC,則可以使用操作篩選器將自定義標頭添加到響應中。像這樣:

public class HttpHeaderAttribute : ActionFilterAttribute 
{ 
    public HttpHeaderAttribute(string name, string value) 
    { 
     Name = name; 
     Value = value; 
    } 

    public override void OnResultExecuted(ResultExecutedContext filterContext) 
    { 
     filterContext.HttpContext.Response.AppendHeader(Name, Value); 
     base.OnResultExecuted(filterContext); 
    } 

    public string Name { get; set; } 

    public string Value { get; set; } 
} 
+0

我可以使用此MVC作爲IIS中的單獨處理程序嗎? –

相關問題