IW4M-Admin/WebfrontCore/Startup.cs

83 lines
2.7 KiB
C#
Raw Normal View History

2018-02-21 20:29:23 -05:00
using System;
using Microsoft.AspNetCore.Authentication.Cookies;
2018-02-21 20:29:23 -05:00
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace WebfrontCore
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
2018-02-21 20:29:23 -05:00
.AddEnvironmentVariables();
2018-02-21 20:29:23 -05:00
Configuration = builder.Build();
// fixme: this is really really terrible
if (!SharedLibrary.Utilities.IsRunningOnMono())
{
SharedLibrary.Database.DatabaseContext.ConnectionString = Configuration["ConnectionStrings:WindowsConnection"];
}
else
{
SharedLibrary.Database.DatabaseContext.ConnectionString = Configuration["ConnectionStrings:LinuxConnection"];
}
2018-02-21 20:29:23 -05:00
if (!IW4MAdmin.Program.Start())
Environment.Exit(-1);
2018-02-21 20:29:23 -05:00
}
2018-03-09 03:01:12 -05:00
public static IConfigurationRoot Configuration { get; private set; }
2018-02-21 20:29:23 -05:00
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AccessDeniedPath = "/",
AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme,
AutomaticAuthenticate = true,
AutomaticChallenge = true,
LoginPath = "/",
ExpireTimeSpan = TimeSpan.FromDays(30),
});
2018-02-21 20:29:23 -05:00
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
2018-02-21 20:29:23 -05:00
}
}
}