question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor SSR APIs for accessing HttpContext without IHttpContextAccessor

See original GitHub issue

Ideally we’d support things like:

[FromHttpContext] public HttpRequest Request { get; set; }
[FromHttpContext] public HttpResponse Response { get; set; }

This is useful for things like:

  • Reading the HTTP method
  • Reading and writing cookies
  • Setting arbitrary response headers

Issue Analytics

  • State:open
  • Created 3 months ago
  • Reactions:5
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
SteveSandersonMScommented, Jul 21, 2023

I guess it uses the AsyncLocal trick because it’s registered as a singleton. TBH I don’t know why IHttpContextAccessor is registered as singleton and not scoped, but perhaps it’s for back compat reasons. We wouldn’t need to do the same here.

If anyone knows of reasons why we shouldn’t have HttpContext accessible through a scoped service, please say so!

0reactions
DamianEdwardscommented, Aug 21, 2023

I think consistency wins here so sticking with the longer form name until such time we decide to support terser names for all the parameter-source attributes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I access HttpContext in Server-side Blazor?
Thus the only place from which you can access the HttpContext, without even adding the IHttpContextAccessor to the DI container, ...
Read more >
Access HttpContext in ASP.NET Core
Blazor apps run outside of the ASP.NET Core pipeline context. The HttpContext isn't guaranteed to be available within the IHttpContextAccessor, ...
Read more >
How do you use the HttpContext object in Blazor server- ...
Use HttpContext through the IHttpContextAccessor interface to get the user agent details in a Blazor Server application. The following example demonstrates ...
Read more >
Accessing the ASP.NET Core Base URL: So Many Ways
My Specific Situation: Accessing my App's base URL for API calls. If you haven't heard, I've been building a Blazor server app for...
Read more >
Stefan Đokić's Post - dotnet #softwareengineer #csharp
IHttpContextAccessor is an abstraction over the HttpContext object that allows it to be ... NET Core | Web API | Blazor | SQL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found