c# - Sub Web.config in Area -


i'm working on huge mvc 4 project. i'm using area , it's great.

but, want, each areas, use custom web.config.

for example, structure :

root web.config | ----areas --------myarea_1 --------myarea_2 ----web.config 

in root web.config, i've connections. in sub web.config, want add "appsettings" concern areas.

in sub web.config, example :

<appsettings>     <add key="myarea_1_param1" value="1"/>     <add key="myarea_1_param2" value="2"/>      <add key="myarea_2_param1" value="1"/> </appsettings> 

for moment, i've put of parameters in root web.config.

how can make link between different web.config?

------update--------

i've try put code in sub web.config :

<?xml version="1.0" encoding="utf-8"?> <location path="myarea_1">     <appsettings>         <add key="myarea_1_param1" value="1"/>         <add key="myarea_1_param2" value="2"/>     </appsettings> </location> 

a put file, here :

root web.config | ----areas --------myarea_1 --------myarea_2 ----web.config <- here 

i try here :

root web.config | ----areas --------myarea_1 ------------web.config --------myarea_2 

but i'm still getting "nullreferenceexception" when try read key value "myarea_1_param1"

my code read key value :

configurationmanager.appsettings["myarea_1_param1"].tostring() 

you can use:

<location path="myarea">   <appsetttings>     <add key="myarea_1_param1" value="1"/>   </appsettings> </location> 

and put these web.configs under area directories

to access web.config in given area, can use code this:

system.web.configuration.webconfigurationmanager.openwebconfiguration("/areas/myarea1/views/web.config").appsettings.settings["myarea1_param1"].value 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -