简体   繁体   中英

Configuration Error on Updating Web.config

I would like to update the web.config file by C# in windows container.

The following is a function of updating web.config in C#

private void UpdateWebConfigFile()
{
    var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
    var section = (System.Configuration.ConnectionStringsSection)configuration.GetSection("connectionStrings");

    var defaultConnection = section.ConnectionStrings["DefaultConnection"].ConnectionString;
    section.ConnectionStrings["DefaultConnection"].ConnectionString = Environment.ExpandEnvironmentVariables(defaultConnection);

    configuration.Save();
}

but an error occurred in configuration.Save(); that I get the result as following

Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: An error occurred loading a configuration file: Access to the path 'C:\inetpub\wwwroot\tynfsgbl.tmp' is denied.

Source Error:


An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Source File: C:\inetpub\wwwroot\web.config    Line: 0

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3535.0

My question is How to update Web.config in the application of Windows Container? Thank you!

Containers are by design intended to be immutable, and as such, the default user is set to a non-admin account which will not have permissions to modify the IIS directoy.

While you can modify the runtime user to be an admin, this would present another issue due to the way that IIS inside a container is montiored. Changing the web.config would cause IIS to reset the pool, which docker would treat as a process crash and stop the container.

Either you should modify the web.config as part of the container build, or you should use environment variables directly rather than trying to write them into the web.config when the container is running.

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