2018-06-07 00:45:47 +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 Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
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-08 12:26:59 +08:00
|
|
|
|
services.AddCors();
|
2018-06-07 00:45:47 +08:00
|
|
|
|
services.AddLogging(builder => builder.AddFileLogger());
|
|
|
|
|
services.AddConfigurationManager();
|
|
|
|
|
services.AddCacheManager();
|
|
|
|
|
services.AddDBAccessFactory();
|
|
|
|
|
services.AddDataProtection(op => op.ApplicationDiscriminator = "BootstrapAdmin")
|
|
|
|
|
.SetApplicationName("__bd__")
|
|
|
|
|
.DisableAutomaticKeyGeneration()
|
|
|
|
|
.PersistKeysToFileSystem(new DirectoryInfo(ConfigurationManager.AppSettings["KeyPath"]));
|
|
|
|
|
services.AddMvc(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
|
|
|
|
options.Filters.Add<BootstrapAdminExceptionFilter>();
|
|
|
|
|
}).AddJsonOptions(options =>
|
|
|
|
|
{
|
|
|
|
|
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
|
|
|
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
|
});
|
|
|
|
|
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.UseBrowserLink();
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
app.UseExceptionHandler("/Home/Error");
|
|
|
|
|
}
|
2018-06-08 21:12:02 +08:00
|
|
|
|
app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials());
|
2018-06-07 00:45:47 +08:00
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseCacheManagerCorsHandler();
|
|
|
|
|
app.UseBootstrapRoleAuthorization();
|
|
|
|
|
app.UseMvc(routes =>
|
|
|
|
|
{
|
|
|
|
|
routes.MapRoute(
|
|
|
|
|
name: "default",
|
|
|
|
|
template: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|