2017-06-13 31 views
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并尝试阅读?我如何解决这个问题?

+0

[请勿将问题标题置于](https://stackoverflow.com/help/tagging) – Liam

回答

0

看起来.UseApplicationInsights()扩展名是试图访问加密文件的扩展名。从管道中删除这个解决了这个问题。