一、先定義一個類app
using Microsoft.AspNetCore.Http; namespace BCode.Util { public class MvcContext { public static IHttpContextAccessor httpContextAccessor; public static HttpContext GetContext() { HttpContext context = httpContextAccessor.HttpContext; return context; } } }
二、再啓動類中指定ui
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHttpContextAccessor svp, IAntiforgery antiforgery) { MvcContext.httpContextAccessor = svp; }