aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

IServerAddressesFeature missing in ASP.NET Core 2.2

Open johnavery opened this issue 7 years ago • 2 comments

Hi, I recently upgraded from ASP.NET Core 2.1 to 2.2. As described here and here, I should be able to extract the base address of the service, like so, and was able to up until the upgrade.

public void Configure(IApplicationBuilder app, IHostingEnvironment env) { IServerAddressesFeature serverAddressesFeature = app.ServerFeatures.Get<IServerAddressesFeature>();

string serviceBaseUri = serverAddressesFeature.Addresses.First();

}

Now that I have switched over to the recommended 'InProcess' hosting model for 2.2, the IApplicationBuilder.ServerFeatures collection is null. However, if I switch over to 'OutOfProcess', using the AspNetCoreModule (not V2), the collection is populated once again with the base address.

Am I missing something?

johnavery avatar Mar 05 '19 22:03 johnavery

Hey thanks for reaching out. This is a known feature gap in the InProcess hosting mode that was fixed in 3.0. https://github.com/aspnet/AspNetCore/commit/45d1c054b2bf1d4df33c98c5a3de88417c9cf1bd. If you need the ServerAddress feature, we would recommend either upgrading to 3.0 preview or reverting to OutOfProcess.

jkotalik avatar Mar 05 '19 22:03 jkotalik

Ah, thank you @jkotalik for your prompt response! I will note this in my code and go with the OutOfProcess model for the time being as you suggest.

johnavery avatar Mar 05 '19 22:03 johnavery