我想在.aspx
中的.ashx
和IHttpModule
文件的回复中添加一些标题。如何在.axd
中过滤IsSystemHandler()
和所有其他系统处理程序?我HttpContext.Current.Handler is Page
可以.aspx
,.ashx
怎么办?
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?
}
}
答案 0 :(得分:0)
bool IsSystemHandler()
{
Type t = context.Handler.GetType();
while (t != null && t.Assembly != this.GetType().Assembly)
t = t.BaseType;
if (t == null)
return true;
return false;
}