.NetCore获取上下文HttpContext

coding

1、先定义一个类

using Microsoft.AspNetCore.Http;

namespace BCode.Util

{

publicclass MvcContext

{

publicstatic IHttpContextAccessor httpContextAccessor;

publicstatic HttpContext GetContext()

{

HttpContext context = httpContextAccessor.HttpContext;

return context;

}

}

}

2、再启动类中指定

publicvoid Configure(IApplicationBuilder app, IWebHostEnvironment env, IHttpContextAccessor svp, IAntiforgery antiforgery)

{

MvcContext.httpContextAccessor = svp;

}

以上是 .NetCore获取上下文HttpContext 的全部内容, 来源链接: utcz.com/z/509674.html

回到顶部