sharptooth
sharptooth

Reputation: 170489

404 when I try to open the site from the machine where Azure web role is deployed

At the end of RoleEntryPoint.OnStart() I want to open the web role site to ensure that it doesn't break with some stupid error. So I do the following:

WebRequest request = WebRequest.Create( "http://127.0.0.1" );
using( WebResponse response = request.GetResponse() ) {
}

and this fails with WebException with (404) Not Found text. The role has an open HTTP endpoint on port 80, so this should not be a problem. However if I omit that code and the role starts I can open http://mysubdomain.cloudpapp.net no problem.

What's the deal here? How do I open the web page of the web role site from within the web role?

Upvotes: 0

Views: 181

Answers (1)

astaykov
astaykov

Reputation: 30903

You shall not use 127.0.0.1, but instead the InputEndpoint specified for the WebRole.

You can get the IPEndpoint instance from it with sode like:

RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["YourInputEndpointForWebRole"].IPEndpoint

Then get the IP Address from the IPEndpoint instace.

EDIT

Just double checked to confirm the reason:

The reason for that is that the Site Bindings for the WebSite in IIS are not *:80 (like some nomrally do in local IIS) but just to the specific DIP (Direct (internal) IP Address) of the Instance.

Upvotes: 2

Related Questions