增加后台功能
This commit is contained in:
+51
-2
@@ -1,11 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Unicode;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.WebEncoders;
|
||||
using COMCMS.Common;
|
||||
using COMCMS.Web.Models;
|
||||
using COMCMS.Web.Common;
|
||||
|
||||
namespace COMCMS.Web
|
||||
{
|
||||
@@ -21,12 +29,36 @@ namespace COMCMS.Web
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
//注入自己的HttpContext
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
services.AddMvc().AddSessionStateTempDataProvider();
|
||||
//添加Session 服务
|
||||
services.AddSession();
|
||||
//部分系统配置
|
||||
services.Configure<SystemSetting>(Configuration.GetSection("SystemSetting"));
|
||||
|
||||
services.AddMvc();
|
||||
//防止汉字被自动编码
|
||||
services.Configure<WebEncoderOptions>(options =>
|
||||
{
|
||||
options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
|
||||
});
|
||||
//记录错误
|
||||
services.AddMvc(options =>
|
||||
{
|
||||
options.Filters.Add<HttpGlobalExceptionFilter>();
|
||||
});
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider svp)
|
||||
{
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
context.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN");
|
||||
await next();
|
||||
});
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseBrowserLink();
|
||||
@@ -36,15 +68,32 @@ namespace COMCMS.Web
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
|
||||
//启用Session
|
||||
app.UseSession();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
name: "areas",
|
||||
template: "{area:exists}/{controller=Index}/{action=Index}/{id?}"
|
||||
);
|
||||
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
|
||||
});
|
||||
|
||||
//使用环境变量
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||
});
|
||||
|
||||
//加入HttpContext
|
||||
MyHttpContext.ServiceProvider = svp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user