![](/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.