简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM