DocSpace-client/products/ASC.Calendar/Server/Startup.cs

137 lines
4.4 KiB
C#
Raw Normal View History

2020-02-12 07:58:31 +00:00
using System;
using ASC.Api.Core.Auth;
using ASC.Api.Core.Core;
using ASC.Api.Core.Middleware;
using ASC.Common.DependencyInjection;
using ASC.Common.Logging;
using ASC.Common.Threading.Progress;
using ASC.Common.Threading.Workers;
using ASC.Data.Reassigns;
using ASC.Calendar.Controllers;
using ASC.Web.Core.Users;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
2020-02-27 14:15:25 +00:00
using ASC.Common;
2021-04-13 08:40:31 +00:00
using ASC.Api.Core;
using ASC.Calendar.BusinessObjects;
using ASC.Calendar.Core;
using ASC.Calendar.Models;
2020-02-12 07:58:31 +00:00
namespace ASC.Calendar
{
2021-04-13 08:40:31 +00:00
public class Startup : BaseStartup
2020-02-12 07:58:31 +00:00
{
2021-04-13 08:40:31 +00:00
2020-02-12 07:58:31 +00:00
public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment)
2021-04-13 08:40:31 +00:00
: base(configuration, hostEnvironment)
2020-02-12 07:58:31 +00:00
{
2021-04-13 08:40:31 +00:00
}
2020-02-12 07:58:31 +00:00
2021-04-13 08:40:31 +00:00
public override void ConfigureServices(IServiceCollection services)
{
2020-02-12 07:58:31 +00:00
services.AddMemoryCache();
services.AddDistributedMemoryCache();
services.AddSession();
services.AddAuthentication("cookie")
.AddScheme<AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a => { })
.AddScheme<AuthenticationSchemeOptions, ConfirmAuthHandler>("confirm", a => { });
var builder = services.AddMvc(config =>
{
var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
config.Filters.Add(new AuthorizeFilter(policy));
config.Filters.Add(new TypeFilterAttribute(typeof(TenantStatusFilter)));
config.Filters.Add(new TypeFilterAttribute(typeof(PaymentFilter)));
config.Filters.Add(new TypeFilterAttribute(typeof(IpSecurityFilter)));
config.Filters.Add(new TypeFilterAttribute(typeof(ProductSecurityFilter)));
config.Filters.Add(new CustomResponseFilterAttribute());
config.Filters.Add(new CustomExceptionFilterAttribute());
config.Filters.Add(new TypeFilterAttribute(typeof(FormatFilter)));
config.OutputFormatters.RemoveType<XmlSerializerOutputFormatter>();
config.OutputFormatters.Add(new XmlOutputFormatter());
});
2021-04-13 08:40:31 +00:00
DIHelper.TryAdd<CalendarController>();
DIHelper.TryAdd<DataProvider>();
DIHelper.TryAdd<EventHistory>();
DIHelper.TryAdd<ExportDataCache>();
DIHelper.TryAdd<CalendarWrapper>();
DIHelper.TryAdd<EventWrapper>();
DIHelper.TryAdd<EventWrapper>();
2020-02-27 14:15:25 +00:00
var diHelper = new DIHelper(services);
diHelper
2020-02-12 07:58:31 +00:00
.AddCookieAuthHandler()
.AddCultureMiddleware()
.AddIpSecurityFilter()
.AddPaymentFilter()
.AddProductSecurityFilter()
.AddTenantStatusFilter();
2020-02-27 14:15:25 +00:00
diHelper.AddNLogManager("ASC.Api", "ASC.Web");
2020-02-12 07:58:31 +00:00
2020-02-27 14:15:25 +00:00
diHelper
2020-02-12 07:58:31 +00:00
.AddCalendarController();
services.AddAutofac(Configuration, HostEnvironment.ContentRootPath);
}
2021-04-13 08:40:31 +00:00
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
2020-02-12 07:58:31 +00:00
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseCors(builder =>
builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
app.UseRouting();
app.UseSession();
app.UseAuthentication();
app.UseAuthorization();
app.UseCultureMiddleware();
app.UseDisposeMiddleware();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapCustom();
});
app.UseStaticFiles();
}
}
}