다음을 통해 공유


SiteCollection.Remove(Site) 메서드

정의

사이트 모음에서 지정된 사이트를 제거합니다.

public:
 void Remove(Microsoft::Web::Administration::Site ^ element);
public void Remove (Microsoft.Web.Administration.Site element);
override this.Remove : Microsoft.Web.Administration.Site -> unit
Public Sub Remove (element As Site)

매개 변수

element
Site

Site 개체에서 제거할 SiteCollection 개체입니다.

예외

elementnull 입니다.

예제

다음 예제에서는 사이트를 만들고, 사이트를 제거하고, 구성 시스템을 업데이트합니다.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
using Microsoft.Web.Management;

namespace AdministrationSnippets
{
    class MicrosoftWebAdministrationSite
    {
// Creates an site named HRWeb
public void CreateSite()
{
    CreateSiteByName("HRWeb");
}

// Creates a new site with the specified name
public void CreateSiteByName(string name)
{
    string path = @"C:\inetpub\" + name + "site";

    // Validate the site name
    char[] invalid = SiteCollection.InvalidSiteNameCharacters();
    if (name.IndexOfAny(invalid) > -1)
    {
        Console.WriteLine("Invalid site name: {0}", name);
    }

    // Create the content directory if it doesn't exist.
    if (!System.IO.Directory.Exists(path))
    {
        System.IO.Directory.CreateDirectory(path);
    }

    // Create a new site using the new directory and update the config
    ServerManager manager = new ServerManager();
    try
    {   // Add this site.
        Site hrSite = manager.Sites.Add(name, "http", "*:9090:", path);
        // The site will need to be started manually.
        hrSite.ServerAutoStart = false;
        manager.CommitChanges();
        Console.WriteLine("Site " + name + " added to ApplicationHost.config file.");
    }
    catch
    {
        // A site with this binding already exists. Do not attempt
        // to add a duplicate site.
    }
}
// Creates a site, then deletes it 
public void RemoveSite()
{
    // Create a site to delete first
    CreateSiteByName("HRWeb");

    // Delete the site just created
    RemoveSiteByName("HRWeb");
}
// Deletes a new site based on the name
public void RemoveSiteByName(string siteName)
{
    ServerManager manager = new ServerManager();
    Site siteToRemove = manager.Sites[siteName];
    manager.Sites.Remove(siteToRemove);
    manager.CommitChanges();
    Console.WriteLine("Site " + siteName + " removed from ApplicationHost.config file.");
}
    }
}

설명

개체는 Site 이 호출 중에 메모리의 컬렉션에서 제거됩니다. 그러나 사이트 구성을 구성 시스템에 커밋하려면 클래스를 ServerManager 사용하여 업데이트를 수행해야 합니다.

적용 대상