.Net Core 限制请求大小

方式1:
startup.cs

services.Configure<FormOptions>(options => {
        options.ValueLengthLimit = int.MaxValue;
        options.MultipartBodyLengthLimit = int.MaxValue;
        options.MultipartHeadersLengthLimit = int.MaxValue;
    });

方式2:
program.cs

    // debug时与IIS Express启动模式有冲突
    webBuilder.UseHttpSys(options =>
    {
        options.MaxRequestBodySize = long.MaxValue;
    });
    webBuilder.UseKestrel(options =>
    {
        options.Limits.MaxRequestBodySize = long.MaxValue;
    });

.Net Core Razor Pages 文件上传

表单方式提交单/多文件

public IActionResult OnPost(long id, string subject, List<IFormFile> files)
{
    foreach (var formFile in files)
    {
        if (formFile.Length > 0)
        {
            using (var stream = new FileStream(fileFullPath, FileMode.Create))
            {
                formFile.CopyTo(stream);
            }
        }
    }
}

二进制方式

using (FileStream fs = new FileStream(fileSavePath, FileMode.OpenOrCreate, FileAccess.Write))
{
     MemoryStream ms = new MemoryStream();
     Request.Body.CopyTo(ms);
     ms.Position = 0;
     byte[] buffer1 = new byte[ms.Length];
     ms.Read(buffer1, 0, buffer1.Length);
     ms.Dispose();
     fs.Write(buffer1, 0, buffer1.Length);
}

.Net Core Blazor Server 页面路由

startup.cs中做如下配置

services.AddMvc().AddRazorPagesOptions(options =>
{
      options.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
      options.Conventions.AddPageRoute("/login/login", "/api/login/{id?}");
      options.Conventions.AddPageRoute("/videosms/tpl/edit", "/videosms/tpl/edit/{id?}");
      options.Conventions.AddPageRoute("/videosms/tpl/view", "/videosms/tpl/view/{id?}");
      //options.Conventions.AddPageRoute("/videosms/tpl/add", "/videosms/tpl/add");
})

和默认路由相同的话不要添加, 否则有可能会导致路由匹配冲突.