Why are Url.Action and Request.Url.Host returning "localhost"?

I have a form on a page that is submitted to an external application and I need to submit the url in this post. However, for SOME users, the URL is https: // localhost / Home / MyAction and not https://mysubdomain.domain.com/Home/Action . I haven't been able to reproduce this, but two colleagues are consistently getting this on the same network as me.

<form action="https://externalapp.com/action.cgi" method="POST">
    ...
    <input type="hidden" name="URL" value="@Url.Action("MyAction", "Home", null, "https")"/>
    <input type="submit" value="Submit" />
</form>

      

I tried:

  • Url.Action ("MyAction", "Home", null, "https")
  • Url.Action ("MyAction", "Home", null, "https", Request.Url.Host) // This is what MVC looks like to me if you didn't specify a host
  • Url.Action ("MyAction", "Home", null, "https", Request.Url.Authority)
  • Url.Action ("MyAction", "Home", null, "https", Request.Headers ["host"]) // If you are using a non-standard port, this port will appear twice in the URL (for example https: // mysubdomain.domain.com:4430/Home/Action .

Why do some users see localhost at all with this? None of the users access this application from the server that hosted it.

Update: . Inside the application, the port number is opened, for example https://mysubdomain.domain.com:445/ . Outwardly this is just a normal 443: https://mysubdomain.domain.com/ . For internal users, Url.Action works fine. For external users, even if I point mysubdomain.domain.com to Url.Action it still returns localhost for those accessing it on port 443. I looked at the MVC code for this and I couldn't figure out why it is overwrites my hostname spec.

I checked the HTTPS binding in IIS and was using the correct SSL certificate. I wonder if some port forwarding from external 443 to internal 445 breaks it?

+3


source to share


1 answer


You mention port forwarding in your post. Where is this port forwarding done? If this is done in an IIS window, is it possible that someone configured the forwarding like this:

https://mysubdomain.domain.com:445 -> http://localhost:443

      



This may result in url resolution to use localhost, but no port forwarding occurs internally, so the correct domain is allowed.

+1


source







All Articles