Azure Startup.cmd unable to bind to localhost

174 views Asked by At

Out of the box Azure Web Role seems to bind the website to specific IP Address. As a part of deployment, we need to bind the website to listen to localhost or 127.0.0.1.

I've configured my service definition as below:

<Startup>
      <Task commandLine="Startup.cmd" executionContext="elevated">
        <Environment>
          <Variable name="ComputeEmulatorRunning">
            <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
          </Variable>
        </Environment>
      </Task>
    </Startup>

On Starup.cmd file I've line below:

eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO AzureRoleStartup /D "Executing: BindIISSite.ps1" powershell -NoProfile -ExecutionPolicy unrestricted -Command ".\BindIISSite.ps1"

On BinIISite.ps1 I've PS script below:

import-module WebAdministration
New-WebBinding -Name "*MyWebsite*" -IPAddress "*" -Port 8089 

With all setting above, I noticed that "MyWebSite" is not bound to * for port 8089.

But when I run the startup.cmd manually in Azure VM, it seems to bind correctly. Any idea what may be wrong above?

1

There are 1 answers

4
Joseph Alcorn On

The New-WebBinding cmdlet parameter Name does not accept wildcard characters, so in your script, it is looking for a site with the literal name *MyWebSite*, and that could cause the binding to fail.