yl
2024-06-18 47f5a9401f1e83efeca8b6a5cd28e1da805811f9
VueWebCoreApi/Startup.cs
@@ -7,9 +7,11 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -80,7 +82,6 @@
                string basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
                string xmlPath = Path.Combine(basePath, "VueWebCoreApi.xml");
                c.IncludeXmlComments(xmlPath, true);
            });
            #endregion
@@ -123,6 +124,19 @@
            //设置Cookies
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
            #region 允许大文件上传
            //允许上传大文件
            services.Configure<IISServerOptions>(options =>
            {
                options.MaxRequestBodySize = 1073741824;//此处限制最大1G
            });
            //解决文件上传Multipart body length limit 134217728 exceeded.
            services.Configure<FormOptions>(x =>
            {
                x.ValueLengthLimit = int.MaxValue;
                x.MultipartBodyLengthLimit = 1073741824; //此处限制最大1G
            });
            #endregion 允许大文件上传
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime applicationLeftTime, ILoggerFactory loggerFactory)
@@ -158,13 +172,15 @@
            //添加静态文件中间件
            app.UseDefaultFiles();
            //添加授权文件
            app.UseStaticFiles(new StaticFileOptions() {
                ContentTypeProvider = new FileExtensionContentTypeProvider() {
            app.UseStaticFiles(new StaticFileOptions()
            {
                ContentTypeProvider = new FileExtensionContentTypeProvider()
                {
                    Mappings = {
                        [".xls"] = "application/vnd.ms-excel",
                        [".xls"] = "application/vnd.ms-excel",
                        [".apk"] = "application/vnd.android.package-archive"
                    }
                }
                    }
                }
            });
            app.UseStaticFiles();
            //跨域