如何将.NET Core 5转换为.NET CORE 6转换`configuration.getSection`?
我正在尝试从.NET Core 5转换为.NET Core 6。
在我的.NET Core 5,startup.cs
中,我有
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
// ...
Configuration.GetSection("sectionName")
}
}
.net core 6,startup.cs 已删除。从 https://learn.microsoft.com/en-us/aspnet/core/migration/50-to-migration/50-to-to-migration/50?请参阅如何从配置文件,
appsettings.json
中读取配置
。
您能在.NET 6中找到我可以找到示例的地方吗?
I am trying to convert from .NET Core 5 to .NET Core 6.
In my .NET Core 5, Startup.cs
, I have
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
// ...
Configuration.GetSection("sectionName")
}
}
In .NET Core 6, Startup.cs
is removed. And from https://learn.microsoft.com/en-us/aspnet/core/migration/50-to-60?view=aspnetcore-6.0&tabs=visual-studio , I don't see how can I read Configuration
section from configuration file, appsettings.json
.
Can you please point me where I can find example to do that in .NET 6?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已在程序中配置。
在.NET 6,
配置
或者,您可以使用:
读取
AppSetting.json
中的值。In .Net 6 ,
Configuration
has been configured in Program.cs, You just need to use:to Map appSettings.json object to class.
Or you can just use:
to read the value in
appsetting.json
.