C
C#•3w ago
Yarden

āœ… Is anybody knows how to explain what exactly HttpContext is and its attributes?

In this code:
[Authorize]
[HttpPost("RegisterAsBusiness")]
public async Task<ActionResult> RegisterAsBusiness(BusinessViewModel businessData)
{
//HttpContext represents the current HTTP request and response (of the current cookie -> it's an object provided by ASP.NET Core).
var id = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

var phoneNumber = businessData.Phone;
var ContactEmail = businessData.ContactEmail;
//TODO: var AcceptBusinessTerms = businessData.AcceptBusinessTerms;

if(phoneNumber != null && ContactEmail != null)
{
var user =

}
return Ok();
}
[Authorize]
[HttpPost("RegisterAsBusiness")]
public async Task<ActionResult> RegisterAsBusiness(BusinessViewModel businessData)
{
//HttpContext represents the current HTTP request and response (of the current cookie -> it's an object provided by ASP.NET Core).
var id = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

var phoneNumber = businessData.Phone;
var ContactEmail = businessData.ContactEmail;
//TODO: var AcceptBusinessTerms = businessData.AcceptBusinessTerms;

if(phoneNumber != null && ContactEmail != null)
{
var user =

}
return Ok();
}
Especially here -> var id = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; What exactly is HttpContext? Is it detecting an existing cookie in my enviroment? What User is? Thanks šŸ™‚
4 Replies
Angius
Angius•3w ago
HttpContext is kind of a grab bag of... stuff The request, the response, cookies, headers .User is the currently logged-in user's claims, that are stored in the cookies or in the JWT token
Yarden
YardenOP•3w ago
Thank you ā¤ļø
sibber
sibber•3w ago
in general, "context" means just that, "additional data/stuff related to the thing"
JakenVeina
JakenVeina•3w ago
it's everything that the framework designers thought might be useful to make available to middlewares for processing HTTP requests and building HTTP responses mainly, it consists of the HTTP Request, Response, and Session State pretty much everything on there logically falls into one of those buckets

Did you find this page helpful?