2019-07-01 20:46:08 +08:00
|
|
|
|
using Longbow.Web;
|
2018-10-12 14:23:05 +08:00
|
|
|
|
using Longbow.Web.SignalR;
|
2018-09-16 19:33:56 +08:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
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-10-10 14:54:53 +08:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Serialization;
|
2018-09-16 19:33:56 +08:00
|
|
|
|
using System;
|
2018-09-15 23:55:54 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Client
|
|
|
|
|
{
|
2019-06-24 10:42:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2018-09-15 23:55:54 +08:00
|
|
|
|
public class Startup
|
|
|
|
|
{
|
2019-06-24 10:42:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="configuration"></param>
|
2018-09-15 23:55:54 +08:00
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
Configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-24 10:42:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2018-09-15 23:55:54 +08:00
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
2019-06-24 10:42:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services"></param>
|
2018-09-15 23:55:54 +08:00
|
|
|
|
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());
|
2019-06-21 18:36:25 +08:00
|
|
|
|
services.AddConfigurationManager();
|
|
|
|
|
services.AddCacheManager();
|
2019-01-20 17:10:09 +08:00
|
|
|
|
services.AddDbAdapter();
|
2018-10-15 21:08:54 +08:00
|
|
|
|
services.AddSignalR().AddJsonProtocalDefault();
|
2018-11-03 10:25:44 +08:00
|
|
|
|
services.AddResponseCompression();
|
2019-06-15 22:11:40 +08:00
|
|
|
|
services.AddBootstrapAdminAuthentication();
|
2018-09-16 19:33:56 +08:00
|
|
|
|
services.AddMvc(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
|
|
|
|
options.Filters.Add<ExceptionFilter>();
|
2018-10-10 14:54:53 +08:00
|
|
|
|
}).AddJsonOptions(options =>
|
|
|
|
|
{
|
|
|
|
|
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
|
|
|
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
|
JsonConvert.DefaultSettings = () => options.SerializerSettings;
|
2018-12-05 17:29:09 +08:00
|
|
|
|
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
2018-09-15 23:55:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
2019-06-24 10:42:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="app"></param>
|
|
|
|
|
/// <param name="env"></param>
|
2018-09-15 23:55:54 +08:00
|
|
|
|
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());
|
2018-10-15 21:08:54 +08:00
|
|
|
|
app.UseHttpsRedirection();
|
2018-11-03 10:25:44 +08:00
|
|
|
|
app.UseResponseCompression();
|
2018-09-15 23:55:54 +08:00
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
app.UseCookiePolicy();
|
2019-06-30 23:18:33 +08:00
|
|
|
|
app.UseBootstrapAdminAuthentication();
|
2019-08-10 17:12:45 +08:00
|
|
|
|
app.UseCacheManager();
|
2018-10-15 21:08:54 +08:00
|
|
|
|
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
|
2018-09-15 23:55:54 +08:00
|
|
|
|
app.UseMvc(routes =>
|
|
|
|
|
{
|
|
|
|
|
routes.MapRoute(
|
|
|
|
|
name: "default",
|
|
|
|
|
template: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|