Reputation: 11284
I have an Azure deployment with two sites configured on a single web role, like so:
<WebRole name="Studio" vmsize="Small">
<Sites>
<Site name="Studio" physicalDirectory="..\Studio">
<Bindings>
<Binding name="HttpIn" endpointName="HttpIn" hostHeader="studio.mydomain.localhost" />
</Bindings>
</Site>
<Site name="Admin" physicalDirectory="..\Admin">
<Bindings>
<Binding name="HttpIn" endpointName="HttpIn" hostHeader="admin.mydomain.localhost" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="HttpIn" protocol="http" port="80" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
</WebRole>
I also have the addresses mapped in my hosts file:
127.0.0.1 studio.mydomain.localhost
127.0.0.1 admin.mydomain.localhost
This works fine, and if I test in the browser, using http://studio.mydomain.localhost:81/
and http://admin.mydomain.localhost:81/
, then I get two different index pages, as expected.
But, if I hit F5 in Visual Studio, it insists on trying to launch http://127.0.0.1:81/
, which of course results in a 404 Bad Request error.
Is there any way I can get VS to launch the correct address immediately from F5? It's only a small thing but it's time consuming to have to retype the address each time.
And, while we're on the subject, how does Azure choose which of my roles to launch when I hit F5? I have a web service role in the same Azure project. Why doesn't it try to launch that? Are them some settings I'm missing or is this all controlled by the order things appear in ServiceDefinition.csdef?
I've had a look at the following articles (among others). While both are informative, I can't see the answer to this in either:
http://blog.elastacloud.com/2011/01/11/azure-running-multiple-web-sites-in-a-single-webrole/
http://msdn.microsoft.com/en-us/library/windowsazure/gg433110.aspx
Upvotes: 3
Views: 1453
Reputation: 24895
Actually there is a workaround to start all sites (you'll need to click a button though). First, you need to know how to:
Here is a small app that gets the info, aggregates it, and launches internet explorer (you can improve the code to skip TCP endpoints etc...):
static void Main(string[] args)
{
var document = System.Xml.Linq.XDocument.Load(Path.Combine(args[0], "ServiceDefinition.csdef"));
var siteBindings = from binding in document.Descendants()
where binding.Name.LocalName == "Binding"
select new
{
Role = binding.Parent.Parent.Parent.Parent.Attribute("name").Value,
EndpointName = binding.Attribute("endpointName").Value,
HostHeader = binding.Attribute("hostHeader") != null ? binding.Attribute("hostHeader").Value : null
};
var endpoints = RoleEnvironment.Roles.SelectMany(o => o.Value.Instances)
.SelectMany(o => o.InstanceEndpoints);
foreach (var siteBinding in siteBindings)
{
var endpoint = endpoints.FirstOrDefault(o => o.Value.RoleInstance.Role.Name == siteBinding.Role);
Process.Start("iexplore.exe", String.Format("{0}://{1}:{2}", endpoint.Value.Protocol, siteBinding.HostHeader ?? endpoint.Value.IPEndpoint.Address.ToString(), endpoint.Value.IPEndpoint.Port));
}
}
Now, for the Visual Studio integration, go to Tools, External Tools and add a new application with as arguments $(ProjectDir).
Finally, after starting the debugger, choose the Windows Azure project in your solution explorer, go to Tools and click the Open IExplorer for Azure button. You can even add it to your toolbar.
Upvotes: 3