问题
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