简体   繁体   中英

Switching appSettings file path at runtime in ASP.Net MVC

I have an ASP.Net MVC 2 (C#) project where I want the user to be able to specify which config/appSettings file he would like to use through setting a URL parameter. (mysite?config=someConfig).

I was wondering what was the best way to do this. Is it wise of me to not use ConfigurationManager.AppSettings object at all, and instead create my own configuration manager that can access the URL parameters to decide on which file to read from? Or is it possible for me to override the path used by ConfigurationManager.AppSettings at runtime, so that I can continue using it as before?

Are there any good examples for a good configuration architecture for ASP.Net (MVC) that will support the kind of functionality I am after here? I was thinking this may be a common use case, and that some people may have experience enough on the subject to hint me in the right direction.

Thank you in advance.

Each web application restarts every time you change the underlying Web.config. It's not recommended to change it by user interaction. If you need to store user settings, ASP.NET profiles are the recommended concept.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM