本文介绍了如何从Startup.cs中的XML文件中提取配置设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个startup.cs文件,我想从XML文件而不是appsetings.json文件中提取配置. ASP.NET Core MVC是否可以?

I have a startup.cs file and i want to pull configurations from XML file rather than appsetings.json file. Is it possible with ASP.NET Core MVC?

推荐答案

如果您想使用appsettings.xml,则可以参考我的博客文章此处.

If you want to use an appsettings.xml instead you can refer to my blog article here.

文章引用:

<configuration> <MySettings> <SomeSetting>Test</SomeSetting> <Another>true</Another> </MySettings> </configuration>

<configuration> <MySettings> <SomeSetting>Test</SomeSetting> <Another>true</Another> </MySettings> </configuration>

然后我将其添加为配置的一部分,如下所示:

I then added it as part of configuration like this:

.AddXmlFile("appsettings.xml", optional: true, reloadOnChange: true)

这篇关于如何从Startup.cs中的XML文件中提取配置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 10:19