c# - 更新 Web.config 时出现配置错误
问题描述
我想C#
在 windows 容器中更新 web.config 文件。
以下是C#中更新web.config的功能
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。
推荐阅读
- excel - Excel中的嵌套vlookup?- 获取数组中的特定数字
- python - 如何在时间序列中使用 mean() 并将其放到列中?
- r - R中的子集代码之间存在不同的结果
- javascript - Javascript数组过滤和提取
- azure - 使用变量组和模板的 Azure Pipelines 变量的意外行为
- django - 什么是使您的网站更快的最佳方法,使其加载更快并在 django 中消耗更少的数据
- mysql - 使用 slick 在 mysql 中创建模式时出错
- java - 错误消息:'Offer with PublisherId: 'bitnami' and OfferId: 'wordpress' not found
- c# - C# - 任务始终处于“WaitingForActivation”状态
- bash - 如果在线部分重复,请删除行