简体   繁体   English

在ASP.NET(VS 2005)和web.config中注册程序集

[英]Register assembly in ASP.NET (VS 2005) and web.config

I am applying a new version of an assembly to a web project and have found that I am going to have to replace about 500 instances of the Register Assembly tag at the top of each web control. 我正在将新版本的程序集应用于Web项目,并且发现我将不得不替换每个Web控件顶部的500个Register Assembly标签实例。 I considered registering it in the web.config but when I try this and remove the "Register" tag from the controls, i receive the "unrecognized tag prefix" error as well as losing intellisense for that tag. 我考虑过在web.config中注册它,但是当我尝试这样做并从控件中删除“注册”标签时,我收到“无法识别的标签前缀”错误,并且丢失了该标签的智能感知。 I have not GAC'ed the assemblies but i didnt think that would a problem. 我没有GAC的程序集,但我不认为那会是一个问题。 What am I missing here? 我在这里想念什么? Thanks in advance for any help. 在此先感谢您的帮助。

Are you sure that you are building the config file correctly? 您确定要正确构建配置文件吗? Rick Strahl just wrote an excelent article on this very issue: Rick Strahl就此问题撰写了一篇出色的文章:

http://www.west-wind.com/WebLog/posts/753705.aspx http://www.west-wind.com/WebLog/posts/753705.aspx

Usually when you embed a custom control into a page you need to add a @Register tag like so: 通常,当您将自定义控件嵌入页面时,您需要添加@Register标记,如下所示:

<%@ Page language="c#" Inherits="Westwind.WebToolkit.MessageDisplay" 
                   CodeBehind="MessageDisplay.aspx.cs"  
                   enableViewState="false"   AutoEventWireup="True" 
                   MasterPageFile="~/WestWindWebToolkit.master"
%>
<%@ Register Assembly="Westwind.Web" Namespace="Westwind.Web.Controls" TagPrefix="ww" %>  

in order to get a control to work in the page and show up with Intellisense. 为了使控件能够在页面中工作并与Intellisense一起显示。 If you're using the visual designer to drop controls you probably won't notice this requirement because the designer automatically adds the assembly and namespace dependency for you into the page. 如果使用视觉设计器放置控件,您可能不会注意到此要求,因为设计器会自动为您添加程序集和名称空间依赖项到页面中。 However if you work in markup only as I do mostly, it's often annoying to first have to register the control on the top of the page and then go back to actually embedding the control into the page to get Intellisense. 但是,如果您像我通常所做的那样仅在标记中工作,通常必须先在页面顶部注册控件,然后再回到将控件实际嵌入页面中以获取Intellisense的方法,这通常很烦人。

An easier and application global way to do this is to declare your namespaces and control tags directly in web.config and have them apply globally: 一种更简单的应用程序全局方法是直接在web.config中声明名称空间和控件标签,并将其全局应用:

<system.web>    <pages>
  <namespaces>
    <add namespace="System.IO" />
    <add namespace="System.Text" />
    <add namespace="Westwind.Utilities" />
    <add namespace="Westwind.Web.Controls" />
  </namespaces>
  <controls>
    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add tagPrefix="ww" namespace="Westwind.Web.Controls" assembly="Westwind.Web" />
  </controls>
</pages>    <compilation debug="true">
  <assemblies>
    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
</compilation>
</system.web>

The controls section is what provides effectively the equivalence of the @Register tag in pages and once you've defined the tag prefix there the @Register tag is no longer required in the page. 控件部分有效地提供了@Register标签在页面中的等效性,并且一旦您定义了标签前缀,在页面中就不再需要@Register标签了。

Hope that Helps, 希望能有所帮助,

Jim 吉姆

我必须安装VS 2005 Service Pack 1并重新启动Visual Studio。

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

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