0
我想在我的IHttpModule
中的我的.aspx
和.ashx
文件的響應中添加一些標題。我如何過濾.axd
和IsSystemHandler()
中的所有其他系統處理程序?我可以爲.aspx
做HttpContext.Current.Handler is Page
,但.ashx
呢?確定HttpContext.Current.Handler是我的或系統的
public class MySecurityModule : IHttpModule
{
public void Init(HttpApplication application)
{
application.PreSendRequestHeaders += PreSendRequestHeaders;
}
void PreSendRequestHeaders(object sender, EventArgs e)
{
if (HttpContext.Current.Handler == null)
return;
if (IsSystemHandler())
return;
HttpContext.Current.Response.Headers.Add(.....);
}
bool IsSystemHandler()
{
// How to filter system handlers here?
}
}
雖然此代碼段可以解決的問題,[包括一個解釋](http://meta.stackexchange.com/questions/114762/explaining-entirely-基於代碼-答覆)真的有助於提高你的文章的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 – NathanOliver