【问题标题】:What is the advantage of adding namespace in web.config file?在 web.config 文件中添加命名空间有什么好处?
【发布时间】:2012-05-16 19:36:06
【问题描述】:

web.config文件中添加命名空间有什么好处?

<configuration>
     <system.web>
              <pages>
                <namespaces>
                  <add namespace="System.Collections" />
                </namespaces>
              </pages>
          </system.web>
</configuration>

【问题讨论】:

    标签: c# asp.net .net namespaces web-config


    【解决方案1】:

    这将允许添加您在视图中常用的项目的命名空间,因此您无需在需要使用它们时在每个页面/视图中添加引用。

    【讨论】:

    • 是否只影响网站项目,不影响Web应用项目?
    • 这个命名空间是否也在 c# 代码文件中自动调用?如果我们在 web.config 中添加了命名空间,则无需使用 using 命令在代码文件中添加这些命名空间(如:- using System.Collections)?
    【解决方案2】:

    您在此处定义的命名空间会自动导入到应用程序的所有页面中。

    【讨论】:

      猜你喜欢
      • 2011-11-27
      • 2014-07-17
      • 2011-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 2011-01-20
      相关资源
      最近更新 更多