You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.9 KiB
C#
104 lines
3.9 KiB
C#
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Authorization;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Newtonsoft.Json.Serialization;
|
|
using Quartz.Impl;
|
|
using Quartz.NET.Web.Extensions;
|
|
using Quartz.NET.Web.Filters;
|
|
using Quartz.NET.Web.Utility;
|
|
using System;
|
|
|
|
namespace Quartz.NET.Web
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddAuthentication(options =>
|
|
{
|
|
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
}).AddCookie(options =>
|
|
{
|
|
options.Cookie.HttpOnly = true;
|
|
options.LoginPath = new PathString("/Home/Index");
|
|
// options.LogoutPath = "";
|
|
options.ClaimsIssuer = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
options.SlidingExpiration = true;
|
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
|
|
});
|
|
services.AddHttpClient();
|
|
services.AddControllers()
|
|
.AddNewtonsoftJson(op =>
|
|
{
|
|
op.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
|
|
op.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
|
});
|
|
services.AddMvc(options =>
|
|
{
|
|
var policy = new AuthorizationPolicyBuilder()
|
|
.RequireAuthenticatedUser()
|
|
.Build();
|
|
options.Filters.Add(new AuthorizeFilter(policy));
|
|
});
|
|
services.AddHttpClient();
|
|
services.AddHttpContextAccessor();
|
|
services.AddMvc(options =>
|
|
{
|
|
options.Filters.Add(typeof(TaskAuthorizeFilter));
|
|
});
|
|
services.AddSession().AddMemoryCache();
|
|
services.AddSingleton<IPathProvider, PathProvider>();
|
|
services.AddTransient<HttpResultfulJob>();
|
|
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
|
|
services.AddSingleton<Spi.IJobFactory, IOCJobFactory>();
|
|
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
|
|
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Home/Error");
|
|
app.UseHsts();
|
|
}
|
|
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
|
{
|
|
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
|
});
|
|
app.UseQuartz(env).UseStaticHttpContext();
|
|
app.UseStaticFiles();
|
|
app.UseAuthentication();
|
|
//app.UseMvc();
|
|
app.UseRouting();
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=TaskBackGround}/{action=Index}/{id?}");
|
|
});
|
|
}
|
|
}
|
|
}
|