2018-09-16 19:33:56 +08:00
|
|
|
|
using Bootstrap.Security.Filter;
|
|
|
|
|
using Bootstrap.Security.Middleware;
|
|
|
|
|
using Longbow.Cache;
|
|
|
|
|
using Longbow.Cache.Middleware;
|
|
|
|
|
using Longbow.Configuration;
|
|
|
|
|
using Longbow.Data;
|
|
|
|
|
using Longbow.Logging;
|
|
|
|
|
using Longbow.Web;
|
|
|
|
|
using Longbow.Web.WebSockets;
|
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.DataProtection;
|
2018-09-15 23:55:54 +08:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2018-09-16 19:33:56 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2018-09-15 23:55:54 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Client
|
|
|
|
|
{
|
|
|
|
|
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.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-09-16 19:33:56 +08:00
|
|
|
|
services.AddCors();
|
|
|
|
|
services.AddLogging(builder => builder.AddFileLogger());
|
|
|
|
|
services.AddConfigurationManager();
|
|
|
|
|
services.AddCacheManager();
|
|
|
|
|
services.AddDBAccessFactory();
|
|
|
|
|
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
|
|
|
|
|
.SetApplicationName(Configuration["ApplicationName"])
|
|
|
|
|
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));
|
|
|
|
|
if (Configuration["DisableAutomaticKeyGeneration"] == "True") dataProtectionBuilder.DisableAutomaticKeyGeneration();
|
2018-09-15 23:55:54 +08:00
|
|
|
|
|
2018-09-16 19:33:56 +08:00
|
|
|
|
services.AddMvc(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
|
|
|
|
options.Filters.Add<ExceptionFilter>();
|
|
|
|
|
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
|
|
|
|
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => options.Cookie.Path = "/");
|
2018-09-15 23:55:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
app.UseHsts();
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-16 19:33:56 +08:00
|
|
|
|
app.UseStatusCodePagesWithReExecute("/Home/Error/{0}");
|
|
|
|
|
app.UseCors(builder => builder.WithOrigins(Configuration["AllowOrigins"].Split(',', StringSplitOptions.RemoveEmptyEntries)).AllowAnyHeader().AllowAnyMethod().AllowCredentials());
|
|
|
|
|
//app.UseHttpsRedirection();
|
2018-09-15 23:55:54 +08:00
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
app.UseCookiePolicy();
|
2018-09-16 19:33:56 +08:00
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseBootstrapAdminAuthorization();
|
|
|
|
|
app.UseWebSocketHandler(options => options.UseAuthentication = true);
|
|
|
|
|
app.UseCacheManagerCorsHandler();
|
2018-09-15 23:55:54 +08:00
|
|
|
|
app.UseMvc(routes =>
|
|
|
|
|
{
|
|
|
|
|
routes.MapRoute(
|
|
|
|
|
name: "default",
|
|
|
|
|
template: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|