0

I have an mvc app that has been deployed to our production server. It works well under IIS 8.5 using an IP and an asigned port. But the moment I try to bind it to a subdomain the app starts showing the invalid hostname error.

Tried to see if there was something off in the applicationhost.config but the binding is in the correct format. IP:Port:Binding.

The redirection also works fine, it lands on the page, but it shows the error instead of the login page.

I have deployed sites before, but not MVC apps, and bind them to subdomains and its usually a 2 step process. I dont know what im missing here.

Edit. Here is the screen of the error. Does not say a lot.

Invalid Hostname

  • 1
    "the app starts showing the invalid hostname error", so show the complete error page (even a screen shot). – Lex Li Apr 07 '21 at 23:08
  • There is a similar issue on Github: https://github.com/mariuszkerl/AspNetCoreSubdomain/issues/58 – Ding Peng Apr 08 '21 at 03:04
  • I hope this can help you https://stackoverflow.com/questions/28699538/bad-request-invalid-hostname-with-asp-net-webapi-project-in-visual-studio-2013 and also this https://forums.asp.net/t/2148489.aspx?Bad+Request+Invalid+Hostname – Ali Bacelonia Apr 16 '21 at 03:22

1 Answers1

0

I'm not familiar with MVC or IIS, but base on my experience with other products, you very likely need to tell IIS to preserve the Host header.

Eg. https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/modifying-http-response-headers

In order to be able to modify the HTTP Location header it is necessary to preserve the original value of the HTTP host header. The outbound rewrite rule will use the preserved value when modifying the response. To preserve the original value you will store it in a temporary server variable ORIGINAL_HOST.

You should also make yourself aware about the security vulnerabilities that can result with regard to Host headers. https://techcommunity.microsoft.com/t5/iis-support-blog/host-header-vulnerability/ba-p/1031958

Cameron Kerr
  • 1,725
  • 16
  • 23