c# - Using HttpContextAccessor in a .NET 4.6 project -
i've created .net core project (a class library) targets .net 4.6, needs able access current http context. see can no longer use static httpcontext.current
, , have inject instance of ihttpcontextaccessor
. can still use inside web api project targeting .net 4.6? far, can't httpcontextaccessor.httpcontext
return null.
for class library think might want pass relevant variables/objects via constructor or methods. it's practice, because class library wont break if reference in console app without httpcontext, example.
if you're inside controller method, can use request or response.
Comments
Post a Comment