Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 确定HttpContext.Current.Handler是我的或系统的_Asp.net_Ihttphandler_Ihttpmodule - Fatal编程技术网

Asp.net 确定HttpContext.Current.Handler是我的或系统的

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

我想在IHttpModule中的.aspx和.ashx文件的响应中添加一些头文件。如何筛选.axd和IsSystemHandler中的所有其他系统处理程序?我可以做HttpContext.Current.Handler是.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?
    }
}
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;
}