我有一个简单的.net Web应用程序,并实现了一个基于IHttp的类。我直接从Microsoft文档中复制了该示例。该类位于app_code目录中。
问题是每当我运行应用程序时,我都会收到以下错误:
HttpException(0x80004005):无法加载类型'httpModuleEx.App_Code.HelloWorldClass'
这是我的web.config条目,用于注册新类:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ApplicationInsightsWebTracking"/>
<remove name="HelloWorldClass"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
<add name="HelloWorldClass" type="httpModuleEx.App_Code.HelloWorldClass"/>
</modules>
</system.webServer>
我在这里尝试了很多关于引用HelloWorldClass的变体,但没有一个对我有用。
我还尝试将HelloWorldClass.cs文件(位于app_code目录下)的构建操作“compile”。
以下是HelloWorldClass.cs文件中的代码:
using System;
using System.Web;
namespace httpModuleEx.App_Code
{
public class HelloWordClass : IHttpModule
{
// In the Init function, register for HttpApplication
// events by adding your handlers.
public void Init(HttpApplication application)
{
application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
application.EndRequest += (new EventHandler(this.Application_EndRequest));
}
private void Application_BeginRequest(Object source, EventArgs args)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
string filePath = context.Request.FilePath;
string fileExtension =
VirtualPathUtility.GetExtension(filePath);
if (fileExtension.Equals(".aspx"))
{
context.Response.Write("<h1><font color=red>" +
"HelloWorldModule: Beginning of Request" +
"</font></h1><hr>");
}
}
private void Application_EndRequest(Object source, EventArgs args)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
string filePath = context.Request.FilePath;
string fileExtension =
VirtualPathUtility.GetExtension(filePath);
if (fileExtension.Equals(".aspx"))
{
context.Response.Write("<hr><h1><font color=red>" +
"HelloWorldModule: End of Request</font></h1>");
}
}
public void Dispose()
{
}
}
}
非常感谢任何帮助。
答案 0 :(得分:1)
可能是因为您在代码中将World拼写为Word:)
答案 1 :(得分:0)
是。谢谢!我还将web.config更改为:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ApplicationInsightsWebTracking"/>
<remove name="HelloWorldClass"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
<add name="HelloWorldClass" type="httpModuleEx.App_Code.HelloWorldClass, httpModuleEx"/>
</modules>
</system.webServer>