JXMovies/CMS/JXCMS.CMS.Movie/Startup.cs

117 lines
4.0 KiB
C#
Raw Permalink Normal View History

2020-02-09 19:10:05 +08:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FreeSql;
using JXCMS.CMS.Entity;
using JXCMS.Core;
using JXCMS.Core.Auth;
using JXCMS.Core.Db;
2020-02-16 22:11:24 +08:00
using JXCMS.Core.Log;
2020-02-09 19:10:05 +08:00
using JXCMS.Core.Themes;
2020-02-16 22:11:24 +08:00
using JXCMS.Core.Utils;
2020-02-09 19:10:05 +08:00
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
2020-02-16 22:11:24 +08:00
using Microsoft.AspNetCore.Mvc.Infrastructure;
2020-02-09 19:10:05 +08:00
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
namespace JXCMS.CMS
{
public class Startup
{
public Startup(IConfiguration configuration, IHostEnvironment environment)
{
Configuration = configuration;
Environment = environment;
2020-02-16 22:11:24 +08:00
ConfigHelper.Configs = Configuration;
Log.Init();
2020-02-09 19:10:05 +08:00
}
public IHostEnvironment Environment { get; }
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<RazorViewEngineOptions>(options =>
{
options.AreaViewLocationFormats.Clear();
options.AreaViewLocationFormats.Add("/{2}/Views/{1}/{0}.cshtml");
options.AreaViewLocationFormats.Add("/{2}/Views/Shared/{0}.cshtml");
options.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
options.ViewLocationExpanders.Add(new TemplateViewLocationExpander());
});
services.AddDb(Configuration, Environment.IsDevelopment());
services.AddControllersWithViews().AddRazorRuntimeCompilation();
services.AddJXAuth();
services.AddCms();
2020-02-16 22:11:24 +08:00
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
2020-02-09 19:10:05 +08:00
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
//app.UseHsts();
}
//app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "Admin")),
RequestPath = "/Admin"
});
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "Views")),
RequestPath = "/theme"
});
app.UseJXCMS("/Admin/Install");
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapAreaControllerRoute(
name: "admin", "Admin",
pattern: "Admin/{controller=Home}/{action=Index}/{id?}", new { action = "Index"});
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}