I am using Visual Studio 2013 to Publish a WorkerRole to Azure. The WorkerRole should bind on port 80, and start an Owin WebApp:
WebApp.Start<Startup>(new StartOptions(url: baseUri));
Everything works if I run it locally on the Azure Emulator, but when I run it live on Azure it fails. The relevant Exception is:
Inner Exception: Access is denied
at System.Net.HttpListener.AddAllPrefixes()
at System.Net.HttpListener.Start()
at Microsoft.Owin.Host.HttpListener.OwinHttpListener.Start(HttpListener listener, Func`2 appFunc, IList`1 addresses, IDictionary`2 capabilities, Func`2 loggerFactory)
at Microsoft.Owin.Host.HttpListener.OwinServerFactory.Create(Func`2 app, IDictionary`2 properties)
I tried RDP-ing to the instance and adding the ACL rules which were the usual source of such errors on the local machine
netsh http add urlacl url=http://+:80/ user=Everyone
but unsuccessfully, it still gives the same error.
Has anybody met with this issue and could point me to the right direction for solving it?
Thanks!
It turns out I was binding to "*:80" instead of getting the URI properly from the configuration. So the proper way to get the baseUri to bind on for an Azure Worker is:
var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"];
string baseUri = String.Format("{0}://{1}", endpoint.Protocol, endpoint.IPEndpoint);
and then just bind:
WebApp.Start<Startup>(new StartOptions(url: baseUri));