2012-10-08 17 views
3

我有一個單一的Web角色配置兩個站點的Azure的部署,就像這樣:當我在VS2012中調試時,如何讓Azure模擬器啓動特定的主機頭定義站點?

<WebRole name="Studio" vmsize="Small"> 
    <Sites> 
     <Site name="Studio" physicalDirectory="..\Studio"> 
     <Bindings> 
      <Binding name="HttpIn" endpointName="HttpIn" hostHeader="studio.mydomain.localhost" /> 
     </Bindings> 
     </Site> 
     <Site name="Admin" physicalDirectory="..\Admin"> 
     <Bindings> 
      <Binding name="HttpIn" endpointName="HttpIn" hostHeader="admin.mydomain.localhost" /> 
     </Bindings> 
     </Site> 
    </Sites> 
    <Endpoints> 
     <InputEndpoint name="HttpIn" protocol="http" port="80" /> 
    </Endpoints> 
    <Imports> 
     <Import moduleName="Diagnostics" /> 
    </Imports> 
</WebRole> 

我也有我的主機映射地址文件:

127.0.0.1 studio.mydomain.localhost 
127.0.0.1 admin.mydomain.localhost 

這工作得很好,和如果我在瀏覽器中測試,使用http://studio.mydomain.localhost:81/http://admin.mydomain.localhost:81/,那麼我會得到兩個不同的索引頁面,如預期的那樣。

但是,如果我在Visual Studio中打F5,它堅持嘗試啓動http://127.0.0.1:81/,這當然會導致404錯誤請求錯誤。

有沒有什麼辦法可以讓VS立即從F5啓動正確的地址?這只是一件小事,但每次都必須重新輸入地址是非常耗時的。

而且,當我們談論這個問題時,Azure如何選擇在我碰到F5時啓動哪個角色?我在同一個Azure項目中擁有Web服務角色。爲什麼不嘗試啓動它?他們是我缺少的一些設置還是全部由命令出現在ServiceDefinition.csdef中的命令控制?

我看了下面的文章(其中包括)。雖然兩者都是翔實的,我看不到這個問題的答案在任一:

http://blog.elastacloud.com/2011/01/11/azure-running-multiple-web-sites-in-a-single-webrole/

http://msdn.microsoft.com/en-us/library/windowsazure/gg433110.aspx

+1

沒有,有沒有辦法來指示哪個地址打開瀏覽器視覺工作室。至於其他角色--Windows Azure Tools將啓動項目中的所有角色,但是僅爲Web角色打開了Web瀏覽器,並且沒有其他類型的角色。 – astaykov

+0

Astaykov - 感謝您的信息。 – JcFx

+0

@astaykov - 你想把它放入一個答案,所以我可以接受它嗎?這似乎是正確的。 – JcFx

回答

3

其實存在開始所有站點解決方法(你需要點擊一個按鈕,雖然)。首先,你需要知道如何:

  • 獲取主機頭爲每個站點(服務定義)
  • 獲取當前端口(RoleEnvironment)
  • 獲取網站的當前IP沒有hostheader(RoleEnvironment)

這裏是一個小的應用程序,獲取信息,聚集它,並啓動Internet Explorer的(你可以提高代碼跳過TCP端點等):

static void Main(string[] args) 
    { 
     var document = System.Xml.Linq.XDocument.Load(Path.Combine(args[0], "ServiceDefinition.csdef")); 
     var siteBindings = from binding in document.Descendants() 
          where binding.Name.LocalName == "Binding" 
          select new 
          { 
           Role = binding.Parent.Parent.Parent.Parent.Attribute("name").Value, 
           EndpointName = binding.Attribute("endpointName").Value, 
           HostHeader = binding.Attribute("hostHeader") != null ? binding.Attribute("hostHeader").Value : null 
          }; 

     var endpoints = RoleEnvironment.Roles.SelectMany(o => o.Value.Instances) 
              .SelectMany(o => o.InstanceEndpoints); 

     foreach (var siteBinding in siteBindings) 
     { 
      var endpoint = endpoints.FirstOrDefault(o => o.Value.RoleInstance.Role.Name == siteBinding.Role); 
      Process.Start("iexplore.exe", String.Format("{0}://{1}:{2}", endpoint.Value.Protocol, siteBinding.HostHeader ?? endpoint.Value.IPEndpoint.Address.ToString(), endpoint.Value.IPEndpoint.Port)); 
     } 
    } 

現在,在Visual Studio集成,去工具外部工具,並添加新的應用程序作爲參數$(PROJECTDIR)

enter image description here

最後,啓動調試器後,選擇在Solution Explorer中的Windows Azure項目,去工具,然後單擊打開爲IEXPLORER Azure的按鈕。你甚至可以將它添加到你的工具欄。

enter image description here

相關問題