Skip to content

Commit 0d5fb83

Browse files
author
LemonNoCry
committed
✨ 注册DataProtection fix#361
1 parent e06093c commit 0d5fb83

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

Blog.Core.Api/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
9898

9999
builder.Services.AddSession();
100+
builder.Services.AddDataProtectionSetup();
100101
builder.Services.AddControllers(o =>
101102
{
102103
o.Filters.Add(typeof(GlobalExceptionsFilter));

Blog.Core.Extensions/Blog.Core.Extensions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<PackageReference Include="Com.Ctrip.Framework.Apollo.Configuration" Version="2.10.2" />
1111
<PackageReference Include="Consul" Version="1.7.14.1" />
1212
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.6" />
1314
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
1415
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
1516
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="8.0.0" />
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Blog.Core.Common;
2+
using Blog.Core.Common.Option;
3+
using Microsoft.AspNetCore.DataProtection;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using StackExchange.Redis;
6+
7+
namespace Blog.Core.Extensions.ServiceExtensions;
8+
9+
public static class DataProtectionSetup
10+
{
11+
public static void AddDataProtectionSetup(this IServiceCollection services)
12+
{
13+
var builder = services.AddDataProtection();
14+
15+
var redisOption = App.GetOptions<RedisOptions>();
16+
if (redisOption.Enable)
17+
{
18+
builder.PersistKeysToStackExchangeRedis(App.GetService<IConnectionMultiplexer>());
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)