C
C#2mo ago
op1511

is this a bad practice

var result = await HttpContext.AuthenticateAsync(
CookieAuthenticationDefaults.AuthenticationScheme
);
var result = await HttpContext.AuthenticateAsync(
CookieAuthenticationDefaults.AuthenticationScheme
);
is it bad to access httpcontext directly? what is the alternative?
2 Replies
Becquerel
Becquerel2mo ago
should be fine depending on the context, i.e. if you're in a controller. you can also inject the IHttpContextAccessor through DI if you want an alternative
Becquerel
Becquerel2mo ago
Access HttpContext in ASP.NET Core
Learn about using HttpContext in ASP.NET Core apps. HttpContext isn't thread-safe and can throw an exception when accessed.