你能在一个ASP.NET CORE项目中读取多个.JSON文件吗



我正在处理一个问题,该问题要求我从两个不同的.Json文件中读取,这取决于网页的URL。除了Iconfiguration,我似乎找不到任何其他读取方式。有什么方法可以确定配置的路径吗?比如(/site/webURL/appsetting.json/(,然后选择我想要获得的值的名称(_configuration["privacy:GDPR"](我在读取正常的appsettings时没有问题。我只想知道我是如何从具有特定路径的.json中读取信息的

public static string Getjsonvalue(string hostName = "")
{
string hostNam = string.IsNullOrEmpty(hostName) ? _options.Value.Paths.Defaultsite : hostName.Replace('-', '_').Replace('.', '_');
var rootPath = ("/sites/" + GetSite(hostName) + "/appsetting.json").Replace('\', '/');
var Value =  find configuration["privacy:GDPR"] in rootPath// where i need help
return Value;
}

按路径读取文件的一种方法如下:

string contentRootPath = _hostingEnvironment.ContentRootPath;
var JsonFile = System.IO.File.ReadAllText( contentRootPath + "/yourJsonFile.json");

最新更新