2018-06-12 11:17:21 +08:00
|
|
|
|
using Bootstrap.DataAccess;
|
|
|
|
|
using Bootstrap.Security.Filter;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
using Bootstrap.Security.Middleware;
|
|
|
|
|
using Longbow.Cache;
|
|
|
|
|
using Longbow.Cache.Middleware;
|
|
|
|
|
using Longbow.Configuration;
|
|
|
|
|
using Longbow.Data;
|
|
|
|
|
using Longbow.Logging;
|
2018-06-12 11:17:21 +08:00
|
|
|
|
using Longbow.Web;
|
2018-06-11 18:37:21 +08:00
|
|
|
|
using Longbow.Web.WebSockets;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2018-06-16 14:35:10 +08:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2018-06-11 18:37:21 +08:00
|
|
|
|
using Newtonsoft.Json;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
2018-06-16 14:35:10 +08:00
|
|
|
|
services.Configure<CookiePolicyOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
|
|
|
|
options.CheckConsentNeeded = context => true;
|
|
|
|
|
options.MinimumSameSitePolicy = SameSiteMode.None;
|
|
|
|
|
});
|
2018-06-08 12:26:59 +08:00
|
|
|
|
services.AddCors();
|
2018-06-12 11:17:21 +08:00
|
|
|
|
services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionHelper.Log));
|
2018-06-07 00:45:47 +08:00
|
|
|
|
services.AddConfigurationManager();
|
|
|
|
|
services.AddCacheManager();
|
|
|
|
|
services.AddDBAccessFactory();
|
2018-08-30 13:20:40 +08:00
|
|
|
|
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
|
|
|
|
|
.SetApplicationName(Configuration["ApplicationName"])
|
|
|
|
|
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));
|
|
|
|
|
if (Configuration["DisableAutomaticKeyGeneration"] == "True") dataProtectionBuilder.DisableAutomaticKeyGeneration();
|
2018-06-07 00:45:47 +08:00
|
|
|
|
services.AddMvc(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
2018-06-12 11:17:21 +08:00
|
|
|
|
options.Filters.Add<ExceptionFilter>();
|
2018-06-07 00:45:47 +08:00
|
|
|
|
}).AddJsonOptions(options =>
|
|
|
|
|
{
|
|
|
|
|
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
|
|
|
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
2018-06-11 18:37:21 +08:00
|
|
|
|
JsonConvert.DefaultSettings = () => options.SerializerSettings;
|
2018-06-16 14:35:10 +08:00
|
|
|
|
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
2018-06-07 00:45:47 +08:00
|
|
|
|
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
app.UseExceptionHandler("/Home/Error");
|
2018-06-16 14:35:10 +08:00
|
|
|
|
app.UseHsts();
|
2018-06-07 00:45:47 +08:00
|
|
|
|
}
|
2018-06-11 13:51:50 +08:00
|
|
|
|
app.UseStatusCodePagesWithReExecute("/Home/Error/{0}");
|
2018-06-09 17:04:59 +08:00
|
|
|
|
app.UseCors(builder => builder.WithOrigins(Configuration["AllowOrigins"].Split(',', StringSplitOptions.RemoveEmptyEntries)).AllowAnyHeader().AllowAnyMethod().AllowCredentials());
|
2018-06-16 14:35:10 +08:00
|
|
|
|
app.UseHttpsRedirection();
|
2018-06-07 00:45:47 +08:00
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseBootstrapRoleAuthorization();
|
2018-09-07 15:53:16 +08:00
|
|
|
|
app.UseWebSocketHandler(options => options.UseAuthentication = true, WSHelper.WebSocketMessageHandler);
|
2018-06-09 17:04:59 +08:00
|
|
|
|
app.UseCacheManagerCorsHandler();
|
2018-06-07 00:45:47 +08:00
|
|
|
|
app.UseMvc(routes =>
|
|
|
|
|
{
|
|
|
|
|
routes.MapRoute(
|
|
|
|
|
name: "default",
|
|
|
|
|
template: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-11 19:58:12 +08:00
|
|
|
|
}
|