123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using Cksoft.Unity;
- using Cksoft.Unity.Log4NetConfig;
- using DllEapCommon.Filters;
- using Microsoft.AspNetCore.Authentication.JwtBearer;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.ApplicationParts;
- using Microsoft.AspNetCore.Mvc.Controllers;
- using Microsoft.AspNetCore.Mvc.Formatters;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- using Microsoft.IdentityModel.Tokens;
- using WebUpload.Filters;
- namespace WebUpload
- {
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = 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.Configure<CookiePolicyOptions>(options =>
- {
- // This lambda determines whether user consent for non-essential cookies is needed for a given request.
- options.CheckConsentNeeded = context => true;
- options.MinimumSameSitePolicy = SameSiteMode.None;
- });
- Action<MvcOptions> filters = new Action<MvcOptions>(r =>
- {
- // r.Filters.Add(typeof(WebApiResultMiddleware)); // 格式化 ADT系统 返回数据
- r.Filters.Add(typeof(ExceptionFilterFor));
- //r.Filters.Add(typeof(ButtonFilter));
- r.Filters.Add(typeof(QueryStringFilter));
- // 设置接收和返回值可以为XML格式
- r.InputFormatters.Add(new XmlSerializerInputFormatter(new MvcOptions { }));
- r.OutputFormatters.Add(new XmlSerializerOutputFormatter());
- });
- services.AddMvc(filters).SetCompatibilityVersion(CompatibilityVersion.Version_2_1).ConfigureApplicationPartManager(m =>
- {
- //var fea = new ControllerFeature();
- //var assembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "DllEapBll.dll");
- //var ufpAssembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "DllUfpBll.dll");
- //var mesAssembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "DllDiodesMesBll.dll");
- //m.ApplicationParts.Add(new AssemblyPart(assembly));
- //m.ApplicationParts.Add(new AssemblyPart(ufpAssembly));
- //m.ApplicationParts.Add(new AssemblyPart(mesAssembly));
- //m.PopulateFeature(fea);
- //services.AddSingleton(fea.Controllers.Select(t => t.AsType()).ToArray());
- });
- // services.AddAdtSystem(Configuration);
- var manager = new ApplicationPartManager();
-
- manager.FeatureProviders.Add(new ControllerFeatureProvider());
- var feature = new ControllerFeature();
- manager.PopulateFeature(feature);
- services.AddSingleton(feature.Controllers.Select(t => t.AsType()).ToArray());
- AppConfigurtaionServices.Instance = services.BuildServiceProvider();
- services.AddCors(options =>
- {
- options.AddPolicy("all", builder =>
- {
- builder.AllowAnyOrigin() //允许任何来源的主机访问
- .AllowAnyMethod()
- .AllowAnyHeader()
- .AllowCredentials();//指定处理cookie
- });
- });
-
- services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory factory)
- {
- NLog.ILogger logger = NLog.LogManager.LoadConfiguration("NLog.config").GetCurrentClassLogger();
- NLog.LogManager.Configuration.Variables["connectionString"] = Configuration["eap:ConnectionStrings"];
- Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); //避免日志中的中文输出乱码
- ILogger myloger = factory.AddLog4Net().CreateLogger(typeof(Startup));
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- else
- {
- app.UseExceptionHandler("/Error");
- }
- string errorinfo = "";
- myloger.LogError($"启动服务成功:{errorinfo}");
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- else
- {
- app.UseExceptionHandler("/Home/Error");
- app.UseHsts();
- }
- app.UseCors("all");
- app.UseStaticFiles();
- app.UseCookiePolicy();
- app.UseCors(builder => builder
- .AllowAnyOrigin()
- .AllowAnyMethod()
- .AllowAnyHeader()
- .AllowCredentials());
- app.UseMvc(routes =>
- {
- routes.MapRoute(
- name: "default",
- template: "{controller=Home}/{action=Index}/{id?}");
- });
- //app.UseHttpsRedirection();
- //app.UseStaticFiles();
- //app.UseCookiePolicy();
- //app.UseMvc(routes =>
- //{
- // routes.MapRoute(
- // name: "default",
- // template: "{controller=Home}/{action=Index}/{id?}");
- //});
- }
- }
- }
|