我有一个在 Visual Studio 2008 中构建的 C# Web 应用程序,其中我们严重依赖于 ASP.NET“预构建” block 的用户控件。
我们不是在每个页面上注册一大堆用户控件,而是在本地(到特定文件夹)web.config 文件中注册所有控件。优点是我们可以使用控件,并且页面在源 View 中看起来“更干净”。但是,VS2008 设计 View 和 Intellisense 都无法识别控件在 web.config
中注册的事实。但是,应用程序本身可以按预期工作。
通常在每个页面的顶部我们会有一个像这样的标签:
<%@ Register src="~/CommonControls/Foo.ascx" tagname="Foo" tagprefix="Bar" %>
我们在本地 web.config 中注册控件,如下所示:
<?xml version="1.0"?>
<configuration>
<system.web>
<pages>
<controls>
<add src="~/CommonControls/Foo.ascx" tagName="Foo" tagPrefix="Bar"/>
</controls>
</pages>
</system.web>
</configuration>
有人知道让 Intellisense 识别这些自定义控件的修复方法吗?或者,有“更好”的方法吗?
最佳答案
虽然这在本地 Web.Config 文件中不起作用,但您可以使用根 web.config 文件中的位置标记来实现相同的结果。
例如:
<?xml version="1.0"?>
<configuration>
<location path="MyPath">
<system.web>
<pages>
<controls>
<add src="~/CommonControls/Foo.ascx" tagName="Foo" tagPrefix="Bar"/>
</controls>
</pages>
</system.web>
</location>
</configuration>
关于asp.net - 在 web.config 中注册的 Visual Studio 2008 用户控件未注册智能感知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/438386/