Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

.NET Blazor 9: Capture client ip address

$
0
0

Is anyone able to capture for component use, a client IP address, in Blazor 9 hosted in Azure?

This question has been asked for several years, but for previous Blazor versions; IMHO, there isn't a satisfactory answer that applies to .NET 9 & Blazor. It can't be this difficult.

When running a Blazor interactive server app in Azure, with rendermode of InteractiveServer, it is very difficult to capture the client's IP address.

The first time OnInitialize is hit, there is a valid HttpContext. The second time (render), the HttpContext is null. A HttpContext value captured such as remoteipaddress, even in a scoped service (which is really a singleton in interactive server mode), is gone. HttpContext is missing. Scoped services are reinitialized.

I disabled prerendering, but then the only call to OnInitialized, the HttpContext is null. I get that HttpContext is shady in interactive mode.

Things run stellar in localhost, but once deployed to Azure, the second OnInitialize everything is reinitalized.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>