SiteCollection.InvalidSiteNameCharacters 메서드

정의

사이트 이름에 사용할 수 없는 문자 배열을 검색합니다.

public:
 static cli::array <char> ^ InvalidSiteNameCharacters();
public static char[] InvalidSiteNameCharacters ();
static member InvalidSiteNameCharacters : unit -> char[]
Public Shared Function InvalidSiteNameCharacters () As Char()

반환

Char[]

사이트 이름에 사용할 수 없는 문자 배열입니다.

예제

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

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.
    }
}
    }
}

설명

CLR(공용 언어 런타임)을 실행하는 Windows 운영 체제에서 이 메서드는 \?;:@&=+$,|"<> 문자를 반환합니다.*

적용 대상