Ton*_*nyc 10 identityserver4 asp.net-core-3.0 .net-core-3.0
我有一个 Net Core 2.2 Web Api,我通过 IdentityServer4 的集成来保护它。所以我从IDS4的教程开始写代码,在那里我找到了AddJsonFormatters()。
我正在尝试将它从 .NET Core 2.2 迁移到 .NET Core 3.0。
目前我在 ConfigureServices() 的编译时遇到了问题。
我没有找到 AddJsonFormatters(),如果我理解正确,我必须使用 AddMvcOptions() 来获得相同的结果。
这样对吗?在这种情况下,等效配置是什么?
// .NET Core 2.2
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization()
.AddJsonFormatters();
// Other code...
}
// .NET Core 3.0
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization()
// Something like this...
.AddMvcOptions(options =>
{
//options.OutputFormatters.Add(new SomeKindOf_IOutputFormatter());
//options.InputFormatters.Add(new SomeKindOf_IInputFormatter(options));
});
// Other code...
}
Run Code Online (Sandbox Code Playgroud)
小智 10
您可以使用 Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet 包,并在 Startup.cs 中配置它:
services.AddMvcCore()
.AddNewtonsoftJson(o =>
{
o.SerializerSettings.Converters.Add(new StringEnumConverter());
o.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
})
Run Code Online (Sandbox Code Playgroud)
小智 6
我刚刚发现 IdentityServer4 正在慢慢更新他们的 .NET Core 3.0 示例。附件是您所询问部分的新版本代码的链接,希望对您有所帮助。 https://github.com/IdentityServer/IdentityServer4/blob/master/samples/Quickstarts/1_ClientCredentials/src/Api/Startup.cs
| 归档时间: |
|
| 查看次数: |
5681 次 |
| 最近记录: |