123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using CZFW.Core;
- using CZFW.Framework;
- using CZFW.Framework.Model;
- using CZFW.MDB;
- using CZFW.MDB.Util;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.HttpOverrides;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- namespace CZFW.CMS.Builder
- {
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- ConfigHelper.Configs = configuration;
- }
- 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.AddDbContext<CZDbContext>(options =>
- //{
- // options.UseMySql("Data Source=sp5045a8d445fe0.mysql.rds.aliyuncs.com;user id=sp5045a8d445fe0;password=CZKJggkl3102;Initial Catalog=czfw_db;SslMode=none;",
- // mysqlOptions =>
- // {
- // mysqlOptions.ServerVersion("5.1");
- // }
- // );
- //});
- services.ConfigureFrameworkServices();
- services.ConfigureMDBServices();
- services.AddMemoryCache();
- services.AddSession(options =>
- {
- options.Cookie.Name = "_sid__";
- options.IdleTimeout = TimeSpan.FromMinutes(60);
- });
- services.AddCors(Options =>
- {
- Options.AddPolicy("any", builder =>
- {
- builder.AllowAnyHeader()
- .AllowAnyMethod()
- .AllowAnyOrigin()
- .AllowCredentials();
- });
- });
- services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
- CZHttpContext.ServiceProvider = services.BuildServiceProvider();
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- {
- // loggerFactory.AddLog4Net();
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- else
- {
- app.UseExceptionHandler("/Home/Error");
- }
- app.UseStaticFiles();
- app.UseCookiePolicy();
- app.UseForwardedHeaders(new ForwardedHeadersOptions
- {
- ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
- });
- app.UseSession();
- app.UseMvc(routes =>
- {
- routes.MapRoute(
- name: "resource", template: $"{Constants.RESOURCE_FILE_URL_PREFIX}/{{siteId}}/{{fileType}}/{{fileName}}",
- defaults: new { controller = "Resource", action = "Load" });
- routes.MapRoute(
- name: "content", template: $"{Constants.CONTENT_FILE_URL_PREFIX}/{{tplId}}/{{theme}}/{{folder}}/{{typeFolder}}/{{fileName}}",
- defaults: new { controller = "Resource", action = "Content" });
- routes.MapRoute(
- name: "default",
- template: "{controller=Home}/{action=Index}/{id?}");
- });
- }
- }
- }
|