C# HTTPModule 无法加载 CGI 请求类型

发布于 2024-10-30 13:37:01 字数 2045 浏览 0 评论 0原文

尝试使用我在编译的 C# 类项目中编写的 HTTPModule 来记录请求值并扩展第三方 CGI 购物车。我的模块可以很好地处理 asp、asp.net、jpg 和 html 请求,但是当我请求 store.cgi 时,我收到以下错误。我是否必须在 IIS7 中做一些特殊的事情,或者 HTTPModule 是否不能与 CGI-BIN 中运行的 CGI 可执行文件一起工作?

“/cgi-bin”应用程序中的服务器错误。

无法加载类型“IISWatcher.WatchRequests”。 描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.Web.HttpException:无法加载类型“IISWatcher.WatchRequests”。

源代码:


using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Messaging;

namespace IISWatcher
{
    public class WatchRequests : IHttpModule
    {
        public void Init(System.Web.HttpApplication app)
        {
            app.BeginRequest += new EventHandler(app_BeginRequest);
            app.EndRequest += new EventHandler(app_EndRequest);
        }
        void app_EndRequest(object sender, EventArgs e)
        {
            //HttpApplication app = (HttpApplication)sender;
        }
        void app_BeginRequest(object sender, EventArgs e)
        {
            string strReturn = "\r\n";
            HttpApplication app = (HttpApplication)sender;
            string strAddress = app.Request.UserHostAddress;
            string strUrl = app.Request.Url.AbsoluteUri;
            string strQS = app.Request.QueryString.ToString();
            RequestInfo ri = new RequestInfo();
            System.Diagnostics.EventLog.WriteEntry("HttpModule", 
                "IpAddress: " + strAddress + strReturn + "URL:" + strUrl);
            System.Messaging.MessageQueue msq = new MessageQueue(@".\private$\HttpModuleQueue");
            ri.AbsoluteUri = strUrl;
            ri.IPAddress = strAddress;
            ri.QueryString = strQS;
            msq.Send(ri);
        }

        public void Dispose()
        {
        }
    }
    public class RequestInfo
    {
        public string IPAddress;
        public string AbsoluteUri;
        public string QueryString;
    }
}

IIS7 的 Web.config:

......................

Trying to use a HTTPModule I wrote in complied C# class project to log request values and extend a third party CGI shopping cart. My module works fine with asp,asp.net,jpg and html request, but soon as I request the store.cgi, I get the following error. Do I have to do something special in IIS7 or does HTTPModule not work with a CGI executables running in CGI-BIN?

Server Error in '/cgi-bin' Application.

Could not load type 'IISWatcher.WatchRequests'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Could not load type 'IISWatcher.WatchRequests'.

Source Code:



using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Messaging;

namespace IISWatcher
{
    public class WatchRequests : IHttpModule
    {
        public void Init(System.Web.HttpApplication app)
        {
            app.BeginRequest += new EventHandler(app_BeginRequest);
            app.EndRequest += new EventHandler(app_EndRequest);
        }
        void app_EndRequest(object sender, EventArgs e)
        {
            //HttpApplication app = (HttpApplication)sender;
        }
        void app_BeginRequest(object sender, EventArgs e)
        {
            string strReturn = "\r\n";
            HttpApplication app = (HttpApplication)sender;
            string strAddress = app.Request.UserHostAddress;
            string strUrl = app.Request.Url.AbsoluteUri;
            string strQS = app.Request.QueryString.ToString();
            RequestInfo ri = new RequestInfo();
            System.Diagnostics.EventLog.WriteEntry("HttpModule", 
                "IpAddress: " + strAddress + strReturn + "URL:" + strUrl);
            System.Messaging.MessageQueue msq = new MessageQueue(@".\private$\HttpModuleQueue");
            ri.AbsoluteUri = strUrl;
            ri.IPAddress = strAddress;
            ri.QueryString = strQS;
            msq.Send(ri);
        }

        public void Dispose()
        {
        }
    }
    public class RequestInfo
    {
        public string IPAddress;
        public string AbsoluteUri;
        public string QueryString;
    }
}

Web.config for IIS7:

...................

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文