forked from pojianbing/LazyCaptcha
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (60 loc) · 2.84 KB
/
Program.cs
File metadata and controls
76 lines (60 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using Lazy.Captcha.Core;
using Lazy.Captcha.Core.Generator;
using Sample.NetCore;
using SkiaSharp;
var builder = WebApplication.CreateBuilder(args);
// 内存存储, 基于appsettings.json配置
builder.Services.AddCaptcha(builder.Configuration, options =>
{
// 自定义字体
//options.ImageOption.FontSize = 28;
//options.ImageOption.FontFamily = ResourceFontFamilysFinder.Find("KG HAPPY");
});
// 如果开启随机验码,请打开注释即可。
//builder.Services.Add(ServiceDescriptor.Scoped<ICaptcha, RandomCaptcha>());
// Core项目使用的是IDistributedCache,
// 如果使用redis缓存,需要安装包 Microsoft.Extensions.Caching.StackExchangeRedis
// 参考:https://docs.microsoft.com/zh-cn/aspnet/core/performance/caching/distributed
//builder.Services.AddStackExchangeRedisCache(options =>
//{
// options.Configuration = builder.Configuration.GetConnectionString("RedisCache");
// options.InstanceName = "captcha:";
//});
// Core项目使用的是IDistributedCache,
// 如果使用SQLServer缓存,则安装 Microsoft.Extensions.Caching.SqlServer
//builder.Services.AddDistributedSqlServerCache(options =>
//{
// options.ConnectionString = builder.Configuration.GetConnectionString(
// "DistCache_ConnectionString");
// options.SchemaName = "dbo";
// options.TableName = "TestCache";
//});
// -----------------------------------------------------------------------------
// 全部配置参数,基于代码配置
//builder.Services.AddCaptcha(builder.Configuration, option =>
//{
// option.CaptchaType = CaptchaType.WORD; // 验证码类型
// option.CodeLength = 6; // 验证码长度, 要放在CaptchaType设置后. 当类型为算术表达式时,长度代表操作的个数
// option.ExpirySeconds = 30; // 验证码过期时间
// option.IgnoreCase = true; // 比较时是否忽略大小写
// option.StoreageKeyPrefix = ""; // 存储键前缀
// option.ImageOption.Animation = true; // 是否启用动画
// option.ImageOption.FrameDelay = 30; // 每帧延迟,Animation=true时有效, 默认30
// option.ImageOption.Width = 150; // 验证码宽度
// option.ImageOption.Height = 50; // 验证码高度
// option.ImageOption.BackgroundColor = SKColors.White; // 验证码背景色
// option.ImageOption.BubbleCount = 2; // 气泡数量
// option.ImageOption.BubbleMinRadius = 5; // 气泡最小半径
// option.ImageOption.BubbleMaxRadius = 15; // 气泡最大半径
// option.ImageOption.BubbleThickness = 1; // 气泡边沿厚度
// option.ImageOption.InterferenceLineCount = 2; // 干扰线数量
// option.ImageOption.FontSize = 36; // 字体大小
// option.ImageOption.FontFamily = DefaultFontFamilys.Instance.Actionj; // 字体,中文使用kaiti,其他字符可根据喜好设置(可能部分转字符会出现绘制不出的情况)。
// option.ImageOption.TextBold = true;// 粗体
//});
// 注意: appsettings.json配置和代码配置同时设置时,代码配置会覆盖appsettings.json配置。
builder.Services.AddControllers();
var app = builder.Build();
app.UseStaticFiles();
app.MapControllers();
app.Run();