-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
76 lines (56 loc) · 1.94 KB
/
Program.cs
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 System.Threading.Tasks;
using CMS.Base;
using CMS.DataEngine;
using CMS.Membership;
using Hangfire;
using Kentico.Membership;
using Kentico.Web.Mvc;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKentico();
// Add required Hangfire services.
builder.Services.AddHangfire(c =>
{
// Configure SQL Server as a job storage.
c.UseSqlServerStorage(
// Obtain Kentico Database connection string.
builder.Configuration.GetConnectionString(ConnectionHelper.ConnectionStringName));
});
// Add Hangfire Server which processes background jobs.
builder.Services.AddHangfireServer();
// Setup redirect path for unauthorized requests.
builder.Services.Configure<CookieAuthenticationOptions>(AdminIdentityConstants.APPLICATION_SCHEME, o =>
{
o.LoginPath = "/admin/logon";
});
builder.Services.AddAuthentication();
builder.Services.AddControllersWithViews();
var app = builder.Build();
app.InitKentico();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseKentico();
app.UseAuthorization();
app.MapHangfireDashboard(new DashboardOptions
{
Authorization = []
}).RequireAuthorization("XperienceAdministrationAccessPolicy");
app.Kentico().MapRoutes();
app.MapGet("/", () => "The XperienceByKentico site has not been configured yet.");
// Get IRecurringJobManager service from the application dependency injection container.
var manager = app.Services.GetRequiredService<IRecurringJobManager>();
// Configure desired schedule tasks.
manager.AddOrUpdate("ScheduleTasks.TestJob", () => ScheduleTasks.TestJob(), Cron.Minutely());
app.Run();
class ScheduleTasks
{
public static async Task TestJob()
{
ContextUtils.ResetCurrent();
await UserInfo.Provider.Get().GetEnumerableTypedResultAsync();
}
}