I have the problem reported in the title, that I can reproduce in the following snip of code. I created a new App Server Blazor Project with VS2019 and I slightly modified class WeatherForecastService to report the Client IP Address in the FetchData.Razor page, as follows...
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
{
var rng = new Random();
var v1 = new HttpContextAccessor();
System.Net.IPAddress vIpAddr = new System.Net.IPAddress(0x7f7f7f7f);
if (v1.HttpContext.Connection != null)
vIpAddr = v1.HttpContext.Connection.RemoteIpAddress;
var vAdd = vIpAddr.ToString();
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length )],
CliIP = vAdd
}).ToArray());
}
I have Kestrel Web Server listening (for this application) on port 5050 and on port 5000. If I remotely connect to the webserver on port 5050, all works ok and Client can see it's IP Address, but if the Client connects to the Web Server on port 80 (on which It listens Apache that acts as a reverse proxy for Kestrel listening on port 5000) Kestrel reports the problem "Object reference not set to an instance of an object" on the line:
if (v1.HttpContext.Connection != null)
And in the foot of FetchData.Razor page it is shown: "An error has occurred. This application may no longer respond until reloaded" I suppose that the problem is due to the action of reverse proxy because v1 is destroyed before it needs to be used. Is it so? How can be solved this kind of situation? I need to use Apache as I have multiple web Apps on the same IP address with different hostnames.
Thanks in advance