1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System.Linq;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Http.Features;
- using Microsoft.AspNetCore.Identity;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.SpaServices.Webpack;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- namespace TEAMModelOS
- {
- public class Startup
- {
- public Startup(IConfiguration configuration, IHostingEnvironment env )
- {
- Configuration = configuration;
-
- var builder = new ConfigurationBuilder()
- .SetBasePath(env.ContentRootPath)
- .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
- .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);//增加环境配置文件,新建项目默认有
- this.Configuration = builder.Build();
-
- }
- 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 =>
- //{
- // options.CheckConsentNeeded = context => true;
- // options.MinimumSameSitePolicy = SameSiteMode.None;
- //});
- services.AddMvc(
- //option=> { option.Filters.Add<HttpGlobalExceptionFilter>(); }
- ).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
- //上传文件最大处理
- services.Configure<FormOptions>(x =>
- {
- x.ValueLengthLimit = int.MaxValue;
- x.MultipartBodyLengthLimit = long.MaxValue; // In case of multipart
- x.MultipartHeadersLengthLimit = int.MaxValue;
- });
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- #if DEBUG
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- #else
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- #endif
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- // Webpack initialization with hot-reload.
- app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
- {
- HotModuleReplacement = true,
- });
- }
- 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();
- }
- // 如果你想使用官方认证,必须在上边ConfigureService 中,配置JWT的认证服务 (.AddAuthentication 和 .AddJwtBearer 二者缺一不可)
- app.UseAuthentication();
- app.UseHttpsRedirection();
- app.UseStaticFiles();
- //app.UseCookiePolicy();
- app.UseMvc(routes =>
- {
- routes.MapRoute(
- name: "default",
- template: "{controller=Home}/{action=Index}/{id?}");
- routes.MapSpaFallbackRoute(
- name: "spa-fallback",
- defaults: new { controller = "Home", action = "Index" });
- });
- }
- }
- }
|