Namespace removed in web.config not removed in a page with master

↘锁芯ラ 提交于 2020-01-25 08:39:08

问题


I have defined this in the web.config of a subdirectory

<namespaces>
   <remove namespace="App"/>
   <add namespace="Tom"/>
</namespaces>

App is imported in the parent web.config file, Tom and App have classes with the same names.

To avoid errors resulting from ambiguous class names I removed the App namespace from the sub-directory where the Tom namespace is used.

However the namespace App is still imported on content pages that have a master page outside the Tom directory. This causes the aforementioned errors.

Here is my dir structure

-Root Directory 
--Default.master
--web.config (App is added in web.config)
--Tom Sub-diretory
---web.config (App is removed in web.config)
---Content page that uses Default.master (Here is the problem)
---Page without master (Works OK)

Any solutions?


回答1:


Suppose you have the following in the root web.config:

<namespaces>
    <add namespace="App" />
    <add namespace="Tom" />
</namespaces>

And in your sub web.config:

<namespaces>
    <remove namespace="App" />
    <add namespace="Tom" />
</namespaces>

There will be no problem to use the class in .aspx pages in the sub-folder even if they derive from a master page in the root folder but you won't be able to use it in the master page. In the root master page you will need to fully qualify the type: <%= App.DuplicateType %> or <%= Tom.DuplicateType %>.




回答2:


What about explicitly prefix the usages with the namespace? That should always work.



来源:https://stackoverflow.com/questions/3694068/namespace-removed-in-web-config-not-removed-in-a-page-with-master

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!