简体   繁体   中英

How to configure external config file in Asp.net MVC?

I have an application in which all configuration like connection string, app-setting etc present in my web.config file. In the production environment, when I change some setting. I have to restart the application. I read somewhere that if we add external config file and add it's reference in web.config then we don't need to restart the application. Here is my web.config:

 <appSettings configSource="appSettingConfig.xml" />

Here is my external config file:

<appSettings>
    <add key="IsShowReportEnabled" value ="True"/>
    <add key="SendReportToPrinter" value ="False"/>
  </appSettings>

The external config file is working fine but the problem remains same that if I change in the external file I have to restart the application. Then i googled and found that add section to configure restart on external file or not. Here it is in web.config:

<section name='rewrite' type='???' restartOnExternalChanges='false' />

But this also did not help. Can anyone tell me what I am doing wrong?

Can any one tell me what i am doing wrong?

Web.config settings are intended to be application-wide settings that are loaded at application startup. Typically, these settings are changed manually or by the deployment process so it is an acceptable side-effect that the application will restart when they are changed.

Runtime settings are not meant to be stored in the Web.config file. They are typically stored in another persistent location such as a text file or more commonly, in a database.

Your setting names (in particular SendReportToPrinter ) sound like they are user-specific settings, not application-wide settings. I would expect these to be stored in a user-specific table in a database, since they would probably need to be different for every user.

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