在ASP.NET(VS 2005)和web.config中注册程序集 [英] Register assembly in ASP.NET (VS 2005) and web.config

查看:73
本文介绍了在ASP.NET(VS 2005)和web.config中注册程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将新版本的程序集应用于Web项目,并且发现我将不得不替换每个Web控件顶部的500个Register Assembly标签实例.我考虑过在web.config中注册它,但是当我尝试这样做并从控件中删除注册"标签时,我收到无法识别的标签前缀"错误,并且丢失了该标签的智能感知.我没有GAC的程序集,但我不认为那会是一个问题.我在这里想念什么?预先感谢您的帮助.

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. 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. I have not GAC'ed the assemblies but i didnt think that would a problem. What am I missing here? Thanks in advance for any help.

推荐答案

您确定要正确构建配置文件吗?里克·斯特拉尔(Rick Strahl)刚刚就这个问题写了一篇出色的文章:

Are you sure that you are building the config file correctly? Rick Strahl just wrote an excelent article on this very issue:

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

通常,当您将自定义控件嵌入到页面中时,您需要添加@Register标记,如下所示:

Usually when you embed a custom control into a page you need to add a @Register tag like so:

<%@ 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" %>  

,以便使控件在页面中工作并与Intellisense一起显示.如果您使用视觉设计器放置控件,则您可能不会注意到此要求,因为设计器会自动为您添加程序集和名称空间相关性到页面中.但是,如果您像我通常一样只做标记工作,通常会很烦,首先必须在页面顶部注册该控件,然后再返回到将控件实际嵌入到页面中以获取Intellisense的地方.

in order to get a control to work in the page and show up with 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.

一种更简单的应用程序全局方法是直接在web.config中声明名称空间和控件标签,并将其全局应用:

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:

<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>

控件"部分有效地提供了页面中@Register标签的等效性,并且在定义了标签前缀之后,该页面中就不再需要@Register标签了.

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.

希望有帮助,

吉姆

这篇关于在ASP.NET(VS 2005)和web.config中注册程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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