![](/img/trans.png)
[英]C# web application causes 404 error in Azure when deployed from one computer, but not from another
[英]404 when I try to open the site from the machine where Azure web role is deployed
在RoleEntryPoint.OnStart()
的最后,我想打开Web角色站点,以确保它不会因某些愚蠢的错误而中断。 所以我做了以下事情:
WebRequest request = WebRequest.Create( "http://127.0.0.1" );
using( WebResponse response = request.GetResponse() ) {
}
并且使用带有(404) Not Found
文本的WebException
失败。 该角色在端口80上有一个开放的HTTP端点,因此这应该不是问题。 但是,如果我省略该代码并且角色启动,我可以打开http://mysubdomain.cloudpapp.net
没问题。
这是什么交易? 如何从Web角色中打开Web角色站点的Web页面?
您不应使用127.0.0.1,而是使用为WebRole指定的InputEndpoint。
您可以使用sode从中获取IPEndpoint实例:
RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["YourInputEndpointForWebRole"].IPEndpoint
然后从IPEndpoint instace获取IP地址 。
编辑
只需仔细检查以确认原因:
原因是IIS中的WebSite的站点绑定不是*:80(就像在本地IIS中一样),而只是实例的特定DIP(直接(内部)IP地址)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.