1
我創建了AddEncryptedJson
擴展到IConfigurationBuilder
。我用它下面的方式在我startup.cs:WebHostBuilder錯誤加密application.json
var builder = new ConfigurationBuilder()
.SetBasePath(environment.ContentRootPath)
.AddEncryptedJson("appsettings.json")
.AddJsonFile($"appsettings.{environment.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
塊進行加密,如果它沒有被已經加密的appsettings.json文件,並解密它讀取它的設置。 Startup.cs中的所有內容都按預期工作。
然而,當執行跳回出來的Program.cs:
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
它拋出一個System.FormatException
:
System.FormatException: 'Could not parse the JSON file. Error on line number '0': '�(�<�G#[v��_K���'.'
是Program.cs中也在尋找appsettings.json並嘗試閱讀?我如何解決這個問題?
[請勿將問題標題置於](https://stackoverflow.com/help/tagging) – Liam