question

Kmcnet-3080 avatar image
0 Votes"
Kmcnet-3080 asked SamWu-MSFT edited

Setting Port in .Net 5 Web Api and Visual Studio 2019

Hello everyone and thanks for the help in advance. I am new to .Net 5 Web Api and am trying to deploy some very basic services to get started. The production deployment needs to run on a different port, for example 43443. I've read documentation this requires changes to the project configuration in older versions of .Net and VS, but can't find what needs to be done for VS 2019 and .Net 5. Currently receiving HTTP Error 400. The request hostname is invalid. error when running on production machine. Any help would be appreciated.

windows-server-iisdotnet-aspnet-core-webapi
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The port setting are located in the properties/launchSettings.json file in solution explorer. launchSettings.json only controls the port on the development machine. This information is covered in the fundamental docs.

In a production environment, you need to config your host to use port 43443. If you are hosting on IIS then change your site bindings.

116833-capture.png

A 400 error indicates a problem with the HTTP request and also indicates the request made it to the expected port. What URL are you using and how is IIS configured???


0 Votes 0 ·
capture.png (46.8 KiB)

Thanks for the response. Your answer is what I additionally thought, so I am not sure what the problem is. Is did bind the site to the correct port. I left the out of the box swagger and weatherforecast api intact, just to check connectivity. The Url I am navigating to is http://192.168.0.3:43443/swagger/index.html which throws the HTTP Error 400. The request hostname is invalid error.

0 Votes 0 ·

The IP address you shared is local network IP. This is your production server??? Are you accessing the production server from a system on the same network???

My best guess is you configured a Host Name (see the screenshot) but not the IP address. Try entering a * for the Host Name. Unfortunately, it's not clear what you're doing or why. Usually a production server has a production domain name.

You might want to visit IIS support as this seems issue seems to be related to IIS configuration not ASP.NET Core.

0 Votes 0 ·
Show more comments

0 Answers