不能引用从web.config中的自定义事件 [英] Cannot reference custom event from web.config

查看:137
本文介绍了不能引用从web.config中的自定义事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了 MyWebErrorEvent 位于的APP_ code文件夹从 WebErrorEvent 导出自定义事件我的ASP.NET 2.0 Web站点项目。类 MyWebErrorEvent 未包含在命名空间内。我已经把下面的到我的web.config文件:

I've written a custom event MyWebErrorEvent derived from WebErrorEvent located in the App_Code folder of my ASP.NET 2.0 Web Site Project. The class MyWebErrorEvent is not contained within a namespace. I've put the following into my web.config file:

<configuration>
  <system.web>
    <healthMonitoring>
      <eventMappings>
        <add name="Event1" startEventCode="0" endEventCode="2147483647" type="MyWebErrorEvent"/>
      </eventMappings>
    </healthMonitoring>
  </system.web>
</configuration>

在编译时和运行时我得到以下错误:

At compile time and run time I get the following error:

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load type 'MyWebErrorEvent'.

Source Error: 

Line 16: <healthMonitoring>
Line 17: <eventMappings>
Line 18: <add name="Event1" startEventCode="0" endEventCode="2147483647" type="MyWebErrorEvent"/>
Line 19: </eventMappings>
Line 20: </healthMonitoring>

类MyWebErrorEvent确实编译没有错误。任何人都知道如何解决这个问题?

The class MyWebErrorEvent does indeed compile without errors. Anyone know how to fix this?

编辑: http://msdn.microsoft .COM / EN-US /库/ bb398933.aspx 说,这应该自定义事件工作。引述:

http://msdn.microsoft.com/en-us/library/bb398933.aspx says that this should work for custom events. A quote:

添加包含自定义Web事件实施ASP.NET应用程序的bin子目录大会。或者,也可以将事件源$ C ​​$ C文件添加到APP_ code子目录中。

Add the assembly that contains the custom Web event implementation to the Bin subdirectory of the ASP.NET application. Alternatively, you can add the event source code file to the App_Code subdirectory.

但它也表示,这不会对自定义事件提供工作:

However it also says this will not work for custom event providers:

将包含在应用程序的bin子目录自定义提供实现的程序集。你不能把在APP_ code子目录中的供应商来源$ C ​​$ C文件,因为健康监测系统的配置和创造了APP_ code子目录中的任何code文件编译之前。

Put the assembly that contains the custom provider implementation in the application's Bin subdirectory. You cannot put the provider source code file in the App_Code subdirectory, because the health monitoring system is configured and created before any code files in the App_Code subdirectory are compiled.

我猜文档实际上是不正确有关自定义事件,他们必须进入一个assymbly区别于网站。

I'm guessing the documentation is actually incorrect about custom events and they must go into a assymbly distinct from the web site.

推荐答案

(只是猜测这里...)

(Just guessing here...)

有关网站,在APP_ code类不会被编译到运行时。 MyWebErrorEvent不得不动态编译机会之前,你的web.config正在编制。最好的办法是从网站上单独创建一个类库,并从你的网站引用该项目。另一种选择是将其转换为使用Web应用程序,它实际上在编译时编译各类成一个DLL,而不是在运行时动态地发射它们。

For Web Sites, classes in App_Code do not get compiled until runtime. Your Web.config is being compiled before MyWebErrorEvent has had a chance to be dynamically compiled. Your best bet is to create a class library separately from the web site and reference the project from your web site. Another option is to convert to using a Web Application, which actually compiles all types into one DLL at compile time rather than emitting them dynamically at run-time.

这篇关于不能引用从web.config中的自定义事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆