繁体   English   中英

更新 Web.config 时配置错误

[英]Configuration Error on Updating Web.config

我想通过C#容器中的 C# 更新 web.config 文件。

以下是更新C#中的web.config的function

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();
}

configuration.Save(); 我得到的结果如下

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

我的问题是How to update Web.config in the application of Windows Container? 谢谢!

容器在设计上是不可变的,因此,默认用户设置为非管理员帐户,该帐户无权修改 IIS 目录。

虽然您可以将运行时用户修改为管理员,但由于容器内的 IIS 的监控方式,这会带来另一个问题。 更改 web.config 将导致 IIS 重置池,docker 会将其视为进程崩溃并停止容器。

您应该修改 web.config 作为容器构建的一部分,或者您应该直接使用环境变量,而不是在容器运行时尝试将它们写入 web.config。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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