0
A
回答
1
Web角色將在E一Sitesroot文件夾:或F:驅動器,你可以寫的幾行代碼,看看是否能文件夾存在。我無法想通過API的方式。
public static bool IsWebRole()
{
return (System.IO.Directory.Exists(@"E:\sitesroot") || System.IO.Directory.Exists(@"F:\sitesroot"));
}
1
我想你可以從GetHostedService解析從ROLENAME和實例名 /感。確保您製作嵌入式細節 = true以獲取有關服務部署的詳細信息。
更多信息:http://msdn.microsoft.com/en-us/library/windowsazure/ee460806.aspx
+2
好的答案,只要你很樂意按照慣例命名你的角色。 – 2012-01-16 10:56:04
0
使用SDK 2.2,我仍然無法找到不是依賴於角色名字更好,更可靠的解決方案。
public static bool IsWebRole()
{
var roleName = RoleEnvironment.CurrentRoleInstance.Role.Name;
var match = Regex.Match(roleName, ".*webrole.*?", RegexOptions.IgnoreCase);
if (match.Success) return true;
match = Regex.Match(roleName, ".*workerrole.*?", RegexOptions.IgnoreCase);
if (match.Success) return false;
throw new Exception(String.Format("Can't figure out role type of {0}", roleName));
}
0
這是來自部署內部。如果「WaWorkerHost」進程存在,則爲工作角色,否則爲網絡角色。您也可以檢查「WaIISHost」。
bool isWorkerRole = false;
foreach (Process proc in Process.GetProcessesByName("WaWorkerHost"))
{
isWorkerRole = true;
}
相關問題
- 1. 我可以爲Azure工作者角色創建插件嗎?
- 2. 您可以從Azure工作者角色連接到Dynamics GP嗎?
- 3. 我可以將工作角色部署到Windows Azure Pack嗎?
- 4. 網絡+工作者角色成本
- 5. 從網絡共享運行(本地)Azure工作者角色
- 6. 角網絡工作者不工作
- 7. Windows Azure - 我可以在同一個虛擬機上運行Web角色和工作者角色嗎?
- 8. Azure雲網絡角色+ AspNetCompiler?
- 9. Azure工作者角色拋出System.IO.FileNotFoundException
- 10. 遠程調試Azure工作者角色
- 11. 如何停止Azure工作者角色
- 12. AzureDirectory與Lucene.Net和Azure工作者角色
- 13. Windows Azure工作者角色和SVG
- 14. Azure文檔Db工作者角色
- 15. Microsoft Azure主從工作者角色
- 16. 工作者角色與Azure批處理
- 17. Windows Azure工作者角色進程
- 18. 在azure工作者角色中的Windows.winmd
- 19. 無法剖析Azure工作者角色
- 20. 喚醒Windows Azure工作者角色
- 21. 關於Azure工作者角色的MongoDB
- 22. 我可以在雲網絡角色項目中使用System.Runtime.Caching.MemoryCache嗎?
- 23. 與Windows Azure中的網絡/工作者角色和實例混淆。
- 24. Windows Azure工作者角色實例是整個虛擬機嗎?
- 25. 工作者角色和Web角色之間的Azure通信
- 26. Azure'網絡角色可以保持活動狀態多久?
- 27. Azure中的網絡和工作人員角色
- 28. Azure工作者角色在與網絡角色的內部tcp連接後變得無響應
- 29. 可控制的Azure工作者角色崩潰恢復
- 30. 以Win表單參與Azure工作者角色後臺服務
您是否想從部署的外部或從部署中知道它? Richard建議在部署中使用。我認爲沒有辦法從部署之外獲取它的類型。 – astaykov 2012-01-16 09:45:54