Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do Url.Action and Request.Url.Host return "localhost"?
    text
    copied!<p>I have a form on a page that posts to an external application and I need to send a URL in that post. However, for SOME users the URL is <a href="https://localhost/Home/MyAction" rel="nofollow">https://localhost/Home/MyAction</a> rather than <a href="https://mysubdomain.domain.com/Home/Action" rel="nofollow">https://mysubdomain.domain.com/Home/Action</a>. I haven't been able to reproduce this, but two coworkers get this consistently on the same network as me.</p> <pre><code>&lt;form action="https://externalapp.com/action.cgi" method="POST"&gt; ... &lt;input type="hidden" name="URL" value="@Url.Action("MyAction", "Home", null, "https")"/&gt; &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p>I've tried:</p> <ul> <li>Url.Action("MyAction", "Home", null, "https")</li> <li>Url.Action("MyAction", "Home", null, "https", Request.Url.Host) // This is what MVC does I believe if you don't specify a host</li> <li>Url.Action("MyAction", "Home", null, "https", Request.Url.Authority)</li> <li>Url.Action("MyAction", "Home", null, "https", Request.Headers["host"]) // If you use a non-standard port, that port would appear twice in the URL (e.g. <a href="https://mysubdomain.domain.com:4430/Home/Action" rel="nofollow">https://mysubdomain.domain.com:4430/Home/Action</a>.</li> </ul> <p>Why would some users see localhost at all with this? None of the users are accessing this application from the server on which it's hosted.</p> <p><strong>Update:</strong> Internally the application is accessed with a port number like <a href="https://mysubdomain.domain.com:445/" rel="nofollow">https://mysubdomain.domain.com:445/</a>. Externally it's just the normal 443: <a href="https://mysubdomain.domain.com/" rel="nofollow">https://mysubdomain.domain.com/</a>. For internal users, Url.Action is working perfectly fine. For external users, even if I specify mysubdomain.domain.com to Url.Action, it's still returning localhost for those accessing using port 443. I looked at the MVC code for this and I couldn't figure out why it would overwrite my hostname specification.</p> <p>I checked the HTTPS binding in IIS and it's using the correct SSL certificate. I wonder if somehow the port forwarding from external 443 to internal 445 is breaking it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload