IW4M-Admin/WebfrontCore/Startup.cs

72 lines
2.3 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();
Configuration = builder.Build();
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 = "/Account/Login/",
AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme,
AutomaticAuthenticate = true,
AutomaticChallenge = true,
LoginPath = "/Account/Login/"
});
2018-02-21 20:29:23 -05:00
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
//app.UseBasicAuthentication(Authentication.Basic.Generate());
2018-02-21 20:29:23 -05:00
}
}
}