简体   繁体   English

使用在Web.Config中注册的程序集而不是在根文件夹中的文件中

[英]Using assemblies registered in Web.Config in files not in root folder

I've registered a control in my web.config file and the .dll for the control has been placed in the application's Bin folder. 我已经在web.config文件中注册了一个控件,该控件的.dll已放置在应用程序的Bin文件夹中。

    <compilation debug="true">
        <assemblies>
            <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="RichTextEditor"/>
        </assemblies>

    </compilation>
    <pages>
        <controls>
            <add assembly="RichTextEditor" namespace="RichTextEditor" tagPrefix="cc1" />
        </controls>
    </pages>

I can now use this control in .aspx pages in the application root folder without issue. 现在,我可以在应用程序根文件夹的.aspx页中使用此控件,而不会出现问题。 However, some of the .aspx pages I want to use this control in are stored in a sub-folder of the application (In this case a sub-folder called "Admin"). 但是,某些我要使用此控件的.aspx页面存储在应用程序的子文件夹中(在这种情况下,子文件夹称为“ Admin”)。 When I try to use these controls in these pages and run in debug I get an error of: 当我尝试在这些页面中使用这些控件并在调试中运行时,出现以下错误:

Error   1   Unknown server tag 'cc1:RichTextEditor'.    N:\IntranetV2\admin\EditMenuItem.aspx   27  

I'm sure I'm missing something simple here but I can't seem to figure out how to get this working and googling doesn't seem to have helped much. 我确定我在这里遗漏了一些简单的东西,但是我似乎无法弄清楚如何使它正常工作,并且谷歌搜索似乎并没有太大帮助。

UPDATE: 更新:

Okay I've tried Aaron's solution with no luck, I amended his code suggestion to: 好的,我没有运气就尝试过亚伦的解决方案,我将他的代码建议修改为:

<add tagPrefix="cc1" tagName="RichTextEditor" src="~/Bin/RichTextEditor.dll" />

I hoped this would be all that's required however I now get the error: 我希望这就是所需要的,但是现在我得到了错误:

Error   1   There is no build provider registered for the extension '.dll'. You can register one in the <compilation><buildProviders> section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.

Please can someone help! 请有人帮忙! I know the answer to this must be ridiculously simple but I'm going mad trying to fix it myself and google has proved no help. 我知道答案必须非常简单,但我为自己解决这个问题而发疯,而Google却证明无济于事。

I had some similar problems a while back. 我前段时间也遇到过类似的问题。 Only way I was able to get the control working was something like this: 我能够使控件正常工作的唯一方式是这样的:

<add tagPrefix="cc1" tagName="RichTextEditor" src="~/controls/richtexteditor.ascx">

rather than this: 而不是这样:

<add assembly="RichTextEditor" namespace="RichTextEditor" tagPrefix="cc1" />

EDIT: 编辑:

Since you're using a binary, add the .dll to your solution, and add a reference to it in the project where you're using it. 由于您使用的是二进制文件,因此请将.dll添加到解决方案中,并在使用它的项目中添加对它的引用。 This way, .NET will add the .dll to your bin folder. 这样,.NET会将.dll添加到您的bin文件夹中。 Then, go back to this (and verify that the namespace and assembly are correct): 然后,返回至此(并验证名称空间和程序集正确):

<add assembly="RichTextEditor" namespace="RichTextEditor" tagPrefix="cc1" />

Also, check this out as a reference: Tip/Trick: How to Register User Controls and Custom Controls in Web.config 另外,请参考以下内容: 提示/技巧:如何在Web.config中注册用户控件和自定义控件

Is the folder defined as an application in IIS? 文件夹是否在IIS中定义为应用程序? That would cause such a problem since in that case IIS will look for web.config (as well as bin/ and other special files and folders) inside that subfolder. 这将导致这样的问题,因为在这种情况下,IIS将在该子文件夹中查找web.config(以及bin /和其他特殊文件和文件夹)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM