views:

56

answers:

2

Hi all,

I'm using following code to open the web.config of my current web application.

Configuration rootConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyAppRoot");

But it only works on my development machine, not production machine. Shall I use something else other than "/MyAppRoot"?

Thanks in advance!

A: 

Your production server is likely to be running in Medium Trust. OpenWebConfiguration will likely fail because it needs to load in Machine.config and the master Web.config file also.

What are you trying to access? You should probably limit access the config file with anything more than ConfigurationSection classes.

Matthew Abbott
A: 

Thank you for your answer, Matthew! I really appreciate it! But I finally found that problem occurs because my application did not run under default site name. The problem was solved by passing httpContext.Request.ApplicationPath rather than "/MyAppRoot" to the OpenWebConfiguration method.

Roy