验证码增加支持分布式缓存功能
This commit is contained in:
parent
2296e83718
commit
6151ec2cec
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
// Lazy.Captcha.Core 组件详细文档(https://api.gitee.com/pojianbing/lazy-captcha/)
|
// Lazy.Captcha.Core 组件详细文档(https://api.gitee.com/pojianbing/lazy-captcha/)
|
||||||
"CaptchaOptions": {
|
"CaptchaOptions": {
|
||||||
|
"CacheType": "Memory", // Memory、Redis
|
||||||
|
"RedisCacheString": "127.0.0.1:6379,password=, defaultDatabase=2", // Redis连接字符串
|
||||||
"CaptchaType": 10, // 验证码类型0、1、2、3、4、5、6、7、8、9、10、11
|
"CaptchaType": 10, // 验证码类型0、1、2、3、4、5、6、7、8、9、10、11
|
||||||
"CodeLength": 1, // 验证码长度, 要放在CaptchaType设置后 当类型为算术表达式时,长度代表操作的个数, 例如2
|
"CodeLength": 1, // 验证码长度, 要放在CaptchaType设置后 当类型为算术表达式时,长度代表操作的个数, 例如2
|
||||||
"ExpirySeconds": 60, // 验证码过期秒数
|
"ExpirySeconds": 60, // 验证码过期秒数
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.16" />
|
<PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.16" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.0" />
|
||||||
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="9.0.0" />
|
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="9.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,7 @@ using System.Linq;
|
|||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Unicode;
|
using System.Text.Unicode;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Admin.NET.Web.Core;
|
namespace Admin.NET.Web.Core;
|
||||||
|
|
||||||
@ -211,6 +212,19 @@ public class Startup : AppStartup
|
|||||||
// 验证码
|
// 验证码
|
||||||
services.AddCaptcha();
|
services.AddCaptcha();
|
||||||
|
|
||||||
|
var captchaCacheType = App.GetService<IConfiguration>().GetSection("CaptchaOptions:CacheType")?.Value;
|
||||||
|
if (captchaCacheType == "Redis")
|
||||||
|
{
|
||||||
|
var connectionString = App.GetService<IConfiguration>().GetSection("CaptchaOptions:RedisCacheString")?.Value;
|
||||||
|
// 如果使用redis分布式缓存
|
||||||
|
services.AddStackExchangeRedisCache(options =>
|
||||||
|
{
|
||||||
|
options.Configuration = connectionString;
|
||||||
|
options.InstanceName = "captcha:";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 控制台logo
|
// 控制台logo
|
||||||
services.AddConsoleLogo();
|
services.AddConsoleLogo();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user