I'm creating a website using MVC3, I'm using the razor syntax to create the views and it's all running under azure.

Currently I'm running under the azure emulator locally.

I have a view at the url: '<http://localhost:81/Blah/Foo>'.

In that view I want to get the Url for another action.

To achieve this I use: Url.Action("SomeAction", "SomeController", null, this.Request.Url.Scheme)

However because of the load balancing the azure emulator does the port number the request is made on changes.

i.e. whilst it's running on port 81, the request might come from port 82.

This leads to to create an incorrect url '<http://localhost:82/Blah/Bar>' and I get a 400, bad hostname error.

Following the info in this post <http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/9142db8d-0f85-47a2-91f7-418bb5a0c675/> I found that I could get the correct host and port number using HttpContext.Request.Headers["Host"].

But I can only pass a host-name to Url.Action, if I try passing the host-name and port then it still appends what it thinks is the right port so I end up with localhost:81:82.

EDIT: I found someone with the same problem. They seem to have gathered the same information I have (except they've included a reproduction too) but they don't have a useful fix as I can't specify the port number manually.

<http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/87c729e8-094c-4578-b9d1-9c8ff7311577/>

I suppose one fix would be to make my own Url.Action overload that lets me specify the port.