123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using CZFW.CMS.Web.App_Code;
- using CZFW.Core;
- using CZFW.Framework;
- using CZFW.Framework.Model;
- using CZFW.MDB;
- using CZFW.MDB.Util;
- using log4net;
- using log4net.Config;
- using log4net.Repository;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http.Features;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- using System;
- using System.IO;
- using System.Text.Encodings.Web;
- using System.Text.Unicode;
- namespace CZFW.CMS.Web
- {
- public class Startup
- {
- public static ILoggerRepository repository { get; set; }
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- ConfigHelper.Configs = configuration;
- repository = LogManager.CreateRepository("NetCoreRepository");
- XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
- App_Code.InitRepository.loggerRepository = repository;
- }
- 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.ConfigureFrameworkServices();
- services.ConfigureMDBServices();
- services.AddMemoryCache();
- services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));
- services.Configure<Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions>(options =>
- {
- options.ViewLocationExpanders.Add(new CZViewLocationExpander());
- });
- //services.AddDbContext<CZDbContext>(options =>
- //{
- // options.UseMySql(ConfigHelper.GetValue<string>("ConnectionStrings:MySql"),
- // mysqlOptions =>
- // {
- // //mysqlOptions.ServerVersion("5.1");
- // }
- // );
- //});
- services.AddSession(options =>
- {
- options.IdleTimeout = TimeSpan.FromMinutes(180);
- });
- services.AddMvc(o => o.Filters.Add(typeof(GlobalExceptions)));
- services.Configure<FormOptions>(options =>
- {
- options.MultipartBodyLengthLimit = 60000000;
- });
- services.AddResponseCaching();
- 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, ILoggerFactory logger)
- {
- app.UseSession();
- //if (env.IsDevelopment())
- //{
- // app.UseDeveloperExceptionPage();
- // app.UseBrowserLink();
- //}
- //else
- //{
- // app.UseExceptionHandler("/Home/Error");
- //}
- app.UseStatusCodePagesWithReExecute("/Home/CodePage/{0}");
- app.UseResponseCaching();
- logger.AddLog4Net();
- logger.AddEventSourceLogger();
- app.UseStaticFiles();
- app.UseMvc(routes =>
- {
- var langs = ConfigHelper.GetValue("Multilanguage:Languages").Split(',', System.StringSplitOptions.RemoveEmptyEntries);
- foreach (var lan in langs)
- {
- var lang = lan.Trim();
- routes.MapRoute(
- name: "error" + lang, template: $"{lang}/home/Error",
- defaults: new { controller = "Home", action = "Error", theme = lang });
- routes.MapRoute(
- name: "CodePage" + lang, template: $"{lang}/home/codepage/{{code?}}",
- defaults: new { controller = "Home", action = "CodePage", theme = lang });
- routes.MapRoute(
- name: "home" + lang, template: $"{lang}",
- defaults: new { controller = "Home", action = "Index", theme = lang });
- routes.MapRoute(
- name: "about" + lang, template: $"{lang}/aboutus",
- defaults: new { controller = "Home", action = "About", theme = lang });
- routes.MapRoute(
- name: "contact" + lang, template: $"{lang}/contact",
- defaults: new { controller = "Home", action = "Contact", theme = lang });
- routes.MapRoute(
- name: "list" + lang, template: $"{lang}/{{pageName}}/{{action}}.html",
- defaults: new { controller = "Data", action = "List", theme = lang });
- routes.MapRoute(
- name: "homeController" + lang, template: $"{lang}/home/{{action}}/{{id?}}",
- defaults: new { controller = "Home", action = "Index", theme = lang });
- routes.MapRoute(
- name: "detail" + lang, template: $"{lang}/{{pageName}}/{{action}}/{{id}}.html",
- defaults: new { controller = "Data", action = "Detail", theme = lang });
- routes.MapRoute(
- name: "data" + lang, template: $"{lang}/{{pageName}}/{{action}}/{{id?}}",
- defaults: new { controller = "Data", action = "List", theme = lang });
- routes.MapRoute(
- name: "default" + lang,
- template: $"{lang}/{{controller=Home}}/{{action=Index}}/{{id?}}");
- }
- var defaultLang = ConfigHelper.GetValue("Multilanguage:Default");
- routes.MapRoute(
- name: "error", template: $"home/Error",
- defaults: new { controller = "Home", action = "Error", theme = "default" });
- routes.MapRoute(
- name: "CodePage", template: $"home/codepage/{{code?}}",
- defaults: new { controller = "Home", action = "CodePage", theme = defaultLang });
- routes.MapRoute(
- name: "home", template: $"",
- defaults: new { controller = "Home", action = "Index", theme = defaultLang });
- routes.MapRoute(
- name: "about", template: $"aboutus",
- defaults: new { controller = "Home", action = "About", theme = defaultLang });
- routes.MapRoute(
- name: "contact", template: $"contact",
- defaults: new { controller = "Home", action = "Contact", theme = defaultLang });
- routes.MapRoute(
- name: "resource", template: $"{Constants.RESOURCE_FILE_URL_PREFIX}/{{siteName}}/{{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: "list", template: "{pageName}/{action}.html",
- defaults: new { controller = "Data", action = "List" });
- routes.MapRoute(
- name: "homeController", template: $"home/{{action}}/{{id?}}",
- defaults: new { controller = "Home", action = "Index", theme = defaultLang });
- routes.MapRoute(
- name: "detail", template: "{pageName}/{action}/{id}.html",
- defaults: new { controller = "Data", action = "Detail" });
- routes.MapRoute(
- name: "data", template: $"{{pageName}}/{{action}}/{{id?}}",
- defaults: new { controller = "Data", action = "List", theme = defaultLang });
- routes.MapRoute(
- name: "default",
- template: $"{{controller=Home}}/{{action=Index}}/{{id?}}");
- //routes.MapRoute(name: "download", template: "en/down.html", defaults: new { controller = "Home", action = "Download" });
- //routes.MapRoute(name: "english", template: "en/{name?}", defaults: new { controller = "Home", action = "English" }, constraints: new { name = @"([a-z]*/)*([a-z0-9]+).html" });
- //routes.MapRoute(
- // name: "home", template: "",
- // defaults: new { controller = "Home", action = "Index" });
- //routes.MapRoute(
- // name: "about", template: "aboutus",
- // defaults: new { controller = "Home", action = "About" });
- //routes.MapRoute(
- // name: "contact", template: "contact",
- // defaults: new { controller = "Home", action = "Contact" });
- //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: "list", template: "{pageName}/{action}.html",
- // defaults: new { controller = "Data", action = "List" });
- //routes.MapRoute(
- // name: "homeController", template: "home/{action}/{id?}",
- // defaults: new { controller = "Home", action = "Index" });
- //routes.MapRoute(
- // name: "detail", template: "{pageName}/{action}/{id}.html",
- // defaults: new { controller = "Data", action = "Detail" });
- //routes.MapRoute(
- // name: "default", template: "{pageName}/{action}/{id?}",
- // defaults: new { controller = "Data", action = "List" });
- });
- }
- }
- }
|