ASP.NET Core App on Azure App Service returns 400 Bad Request with incorrect host and port (https over port 80)

Patrick Brunck 0 Reputation points
2025-04-14T21:47:40.3366667+00:00

Hi, we are hosting an ASP.NET Core application on Azure App Service. After a recent re-deployment (no code changes), I started receiving a "400 (Bad Request)" error when calling an endpoint from JavaScript using a relative path (e.g. /api/SomeEndpoint).

Upon inspecting the detailed error via Azure's "Log stream", I noticed the following:

Requested URL: https://NameOfOurAppService:80/api/SomeEndpoint

This is incorrect — HTTPS should not be used over port 80. This leads to malformed request errors (400) on Azure. We don't explicitly set any port or hostname in the code. We use fetch(...) with relative URLs from within a Razor Page.

The web app was running just fine on Azure for weeks (incl. custom domain with SSL). It is therefore surprising to me that now there is this strange redirect or routing issue. - btw: The same code still works just fine locally.

It seems that Azure is somehow interpreting the request host as NameOfOurAppService:80, which is causing the problem. This behavior did not occur before the redeployment, which makes me suspect something on Azure side has changed (btw: we haven't changed any Azure configs since the previous deployment).

Could you please help identify: Why Azure is resolving the request host to NameOfOurAppService:80 and how to prevent this - or how to resolve our issue?

Any help would be highly appreciated. Thanks!

Best regards,

Patrick

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,672 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Laxman Reddy Revuri 3,990 Reputation points Microsoft External Staff
    2025-04-14T23:52:55.87+00:00

    Hi @Patrick Brunck
    apologize for any inconvenience caused on this.
    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer
    Ask: ASP.NET Core App on Azure App Service returns 400 Bad Request with incorrect host and port (https over port 80)
    Solution: Thanks for your reply! ChatGPT came up with more or less the same proposal, which didn't help, unfortunately. (Above, I also outlined that we made no code changes, and it worked just fine for several weeks and months before. Therefore, it would be really surprising why now additional code for the Program.cs would solve the issue.)

    Meanwhile, I was able to solve the issue, but not sure, what to make out of it. - I witnessed the issue first after re-deploying the solution with our CI/CD pipeline (which also worked just fine for several weeks). After a lot of trial-and-errors, I then decided to re-publish the solution directly from within Visual Studio 2022. That seemed to do the trick. Afterwards, our web app worked just fine again. - I then did another try by re-deploying via CI/CD again. Surprisingly, that CI/CD-deployed version now also causes no issues. - Super strange! But, I would assume that there was some issue on Azure-side, which Microsoft solved in the meantime. Don't know what else could be the issue.

    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members. 


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.