Patrice Manac'h
Patrice Manac'h

Reputation: 81

HttpContext in .Net 8.0

I can't find the package or assembly for that class. Any idea to where I could find that?

I tried to find Microsoft.AspNetCore.Http.Abstractions for .Net 8.0 but no chance...

And I tried to find it in Microsoft documentation, but currently, it's latest version is for .Net 7.0.

Upvotes: 6

Views: 10819

Answers (3)

Post Impatica
Post Impatica

Reputation: 16433

You can add this support in a library but you have to manually paste the following in your *.csproj file of the library.

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

Refer to THIS MS article.

If you are wondering, NO, this does not pull down the package in nuget that is deprecated. This is a framework reference only.

But... I like creating a new .net core webapi project, removing all the files including the program.cs, the launchSettings.json, the appSettings.json then going to the properties of the project and changing it from console to library. This way I get the specific nuget package and it isn't a reference. I have no idea if this is a bad idea or not but it works great.

Upvotes: 0

Heidi Daniels
Heidi Daniels

Reputation: 9

Nothing works; it seems that HttpContext in .net 8 is always null.

Upvotes: 0

Stardog
Stardog

Reputation: 116

I had a same issue and had to declare HttpContext as a cascading parameter at the code section of pages.

[CascadingParameter] public HttpContext? HttpContext { get; set; }

Edit: Found a Microsoft documentation about accessing httpcontext in asp.net 8.0

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/http-context?view=aspnetcore-8.0

Upvotes: 1

Related Questions