开发者

How to open web.config

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 th开发者_JAVA百科an "/MyAppRoot"?

Thanks in advance!


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.


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.


MSDN documentation on this method says that path parameter is

The virtual path to the configuration file. If a null reference (Nothing in Visual Basic), the root Web.config file is opened.

Pass null there and it will open your web.config file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜