Hello! I am doing this tutorial to create a security token in a API
.
The problem I'm having is when calling the class System.Web.HttpContext
, since it directly tells me that HttpContext
it doesn't exist in my current context.
I know that this class comes from system.Web
, and that there are some nugets that give me that class, but the specific property that I want to use from there is HttpContext.Current
, which is not in the nugets Microsoft.AspNet.WebApi
or in Microsoft.AspNet.WebApi.Core
.
This is the code I'm working with:
var tokenHandler = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler();
TokenValidationParameters validationParameters = new()
{
ValidAudience = audienceToken,
ValidIssuer = issuerToken,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
LifetimeValidator = this.LifetimeValidator,
IssuerSigningKey = securityKey
};
// Extract and assign Current Principal and user
Thread.CurrentPrincipal = tokenHandler.ValidateToken(token, validationParameters, out SecurityToken securityToken);
HttpContext.Current.User = tokenHandler.ValidateToken(token, validationParameters, out securityToken); //no reconocido
Does anyone have an idea what might be going on?
According to the documentation ,
HttpContext.Current
it is not available in.Net 5
.In your case you may be referring to another
HttpContext
, try usingSystem.Web.HttpContext.Current
.Here you can find a little more information that will be useful to you.