簡體   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