我试图找出如何删除WebSpace。据我所知,我的订阅中有几个空WebSpaces。我想清理它们。
使用Azure管理库,我可以列出订阅中的网站空间。然后,我可以列出网站以构建包含0个网站的网站空间列表。我没有看到直接删除网站空间的方法。我可以删除WebHostingPlan。
我在下面的代码中遇到的问题是,当我尝试获取给定网站空间的WebHostingPlan时,我什么也得不到。因此,如果没有WebHostingPlan名称,我就无法将其删除。
是否有人不删除网站空间,而只删除WebHostingPlans?我是从错误的观点来看这个吗?
private async static Task DeleteEmptyWebspaces(SubscriptionCloudCredentials credentials)
{
using (var client = new WebSiteManagementClient(credentials))
{
var webspaces = await client.WebSpaces.ListAsync();
IDictionary<string, string> spacesToDelete = new Dictionary<string, string>();
foreach (WebSpacesListResponse.WebSpace space in webspaces)
{
var listWebSiteResponse = await client.WebSpaces.ListWebSitesAsync(space.Name, null);
if (listWebSiteResponse.WebSites.Count == 0)
{
var hostingPlanListResponse = await client.WebHostingPlans.ListAsync(space.Name);
if (hostingPlanListResponse.Any())
{
// Assumption: Only one web hosting plan for a web space. Correct?
spacesToDelete.Add(space.Name, hostingPlanListResponse.WebHostingPlans[0].Name);
}
}
}
foreach (var space in spacesToDelete)
{
var deleteResponse = await client.WebHostingPlans.DeleteAsync(space.Key, space.Value);
if (deleteResponse.StatusCode != HttpStatusCode.OK)
{
Console.WriteLine("Failed to delete '{0}'.", space.Key);
}
}
}
}