【发布时间】:2017-12-03 04:25:00
【问题描述】:
我在Web.config 中有registered two namespaces,就像这样:
<add tagPrefix="a" assembly="WebApplication1" namespace="WebFormsApplication1.Controls1" />
<add tagPrefix="a" assembly="WebApplication1" namespace="WebFormsApplication1.Controls2" />
我在.aspx 页面中这样使用它们:
<a:WebCustomControl1 ID="Control1" runat="server"></a:WebCustomControl1>
<a:WebCustomControl2 ID="Control2" runat="server"></a:WebCustomControl2>
这是 VS 为该页面生成的(损坏的).designer.cs 文件(请注意,它对两个控件都使用 Controls2 命名空间,尽管 Control1 位于 Controls1 命名空间中):
protected global::WebFormsApplication1.Controls2.WebCustomControl1 Control1;
protected global::WebFormsApplication1.Controls2.WebCustomControl2 Control2;
看起来 Web.config 中的第二个 <add 正在覆盖第一个。
我希望它追加而不是覆盖,这可能吗?
我想还有其他选择:
- 将所有内容放在一个命名空间中
- 为每个命名空间使用唯一的
tagPrefix
但它们并不酷,因为我们这里有很多控件。
请注意,如果在 aspx 本身中注册命名空间,它将正常工作:
<%@ Register TagPrefix="a" Namespace="WebFormsApplication1.Controls2" Assembly="WebFormsApplication1" %>
<%@ Register TagPrefix="a" Namespace="WebFormsApplication1.Controls" Assembly="WebFormsApplication1" %>
所以它看起来像Web.config 解析中的一些错误。
(我在 VS 2017 上,但他们告诉我至少从 VS 2010 开始)。
【问题讨论】:
-
不要。由于命名空间阴影,它可能会导致不可预知的结果。
标签: c# asp.net visual-studio webforms