Asp.net 确定HttpContext.Current.Handler是我的或系统的
我想在IHttpModule中的.aspx和.ashx文件的响应中添加一些头文件。如何筛选.axd和IsSystemHandler中的所有其他系统处理程序?我可以做HttpContext.Current.Handler是.aspx的页面,但是.ashx呢Asp.net 确定HttpContext.Current.Handler是我的或系统的,asp.net,ihttphandler,ihttpmodule,Asp.net,Ihttphandler,Ihttpmodule,我想在IHttpModule中的.aspx和.ashx文件的响应中添加一些头文件。如何筛选.axd和IsSystemHandler中的所有其他系统处理程序?我可以做HttpContext.Current.Handler是.aspx的页面,但是.ashx呢 虽然这个代码片段可以解决这个问题,但它确实有助于提高文章的质量。请记住,您将在将来回答读者的问题,这些人可能不知道您的代码建议的原因。 public class MySecurityModule : IHttpModule { pub
虽然这个代码片段可以解决这个问题,但它确实有助于提高文章的质量。请记住,您将在将来回答读者的问题,这些人可能不知道您的代码建议的原因。
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?
}
}
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;
}