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