开发者

How to add namespaces in web.config file?

开发者 https://www.devze.com 2023-04-09 06:18 出处:网络
I am using VS 2008 and C# but when Iadded namespace in web.config file, that namespace is not 开发者_StackOverflowimported or included in code behind or aspx

I am using VS 2008 and C# but when I added namespace in web.config file, that namespace is not 开发者_StackOverflowimported or included in code behind or aspx

I have also read this question but not get the required answer.

web.config code

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


You need to put them in the correct <system.web> section. e.g.:

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

and put them in the correct web.config

i.e. the second web.config file is the Views folder and is specific to views. These settings do not go in the root web.config.

The purpose of these settings is to make the libraries available to the ASPX pages (e.g. for Intellisense) and it is not used for the code-behind. You still need to have using statements in your actual code as that is just plain c# programming.


The purpose of the namespace section is to get around having to do the import in the .aspx page. Code behind in C# still requires you to have the using statements at the top of your .cs file.

There is no way to get around this.

0

精彩评论

暂无评论...
验证码 换一张
取 消