Skip to content

How to retrieve the HttpContext from Blazor server-side ? #14090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
enetstudio opened this issue Sep 18, 2019 · 5 comments
Closed

How to retrieve the HttpContext from Blazor server-side ? #14090

enetstudio opened this issue Sep 18, 2019 · 5 comments
Labels
area-blazor Includes: Blazor, Razor Components question

Comments

@enetstudio
Copy link

Well, I knew that after reading an article by Steve Anderson, but seems to have forgotten that... Thanks in advance.

@MV10
Copy link

MV10 commented Sep 18, 2019

Since Blazor server-side runs over SignalR, there is no HttpContext because HTTP is (usually) not involved.

#12432 (comment)

@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Sep 18, 2019
@mkArtakMSFT
Copy link
Member

Closing this as per @MV10 's answer.

@enetstudio
Copy link
Author

Thanks @MV10 , I actually wanted to know how I can arrive at code like this:

var cookies = Context.GetHttpContext().Request.Cookies;

Context is ConnectionContext , I believe.
And this is a link to the a SignalR class that is supposed to return the HttpClient : https://github.com/aspnet/AspNetCore/blob/3cd5054eb5d8851b25881cd05cccb931aaa022e6/src/SignalR/server/SignalR/src/GetHttpContextExtensions.cs

What I looking for is a way to get client information such as IP address and browser name/version in Blazor server-side?

Thanks...

@MV10
Copy link

MV10 commented Sep 18, 2019

@enetstudio are you maybe thinking of this discussion? You said you saw something from @SteveSandersonMS about this, I happened across this recently while trying to discover whether the SignalR circuit info was exposed.

Edit: Oops I guess Steve wasn't in that discussion...

#5330

@enetstudio
Copy link
Author

Thanks @MV10, I've seen the thread you linked to as well as this one: aspnet/SignalR#1114

As I've said above, I am looking for a way to get client information such as IP address and browser name/version in Blazor server-side... I want to do something like: var cookies = Context.GetHttpContext().Request.Cookies; in my Blazor code. Note that Context is ConnectionContext, but how do I access the ConnectionContext ? This is what I'm trying to find out...

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components question
Projects
None yet
Development

No branches or pull requests

4 participants