注册DataProtection fix#361

This commit is contained in:
LemonNoCry 2024-06-12 14:55:39 +08:00
parent e06093cfbd
commit 0d5fb831de
No known key found for this signature in database
3 changed files with 23 additions and 0 deletions

View File

@ -97,6 +97,7 @@ builder.Services.Configure<KestrelServerOptions>(x => x.AllowSynchronousIO = tru
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
builder.Services.AddSession();
builder.Services.AddDataProtectionSetup();
builder.Services.AddControllers(o =>
{
o.Filters.Add(typeof(GlobalExceptionsFilter));

View File

@ -10,6 +10,7 @@
<PackageReference Include="Com.Ctrip.Framework.Apollo.Configuration" Version="2.10.2" />
<PackageReference Include="Consul" Version="1.7.14.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="8.0.0" />

View File

@ -0,0 +1,21 @@
using Blog.Core.Common;
using Blog.Core.Common.Option;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.DependencyInjection;
using StackExchange.Redis;
namespace Blog.Core.Extensions.ServiceExtensions;
public static class DataProtectionSetup
{
public static void AddDataProtectionSetup(this IServiceCollection services)
{
var builder = services.AddDataProtection();
var redisOption = App.GetOptions<RedisOptions>();
if (redisOption.Enable)
{
builder.PersistKeysToStackExchangeRedis(App.GetService<IConnectionMultiplexer>());
}
}
}