Share via


SiteCollection.InvalidSiteNameCharacters Méthode

Définition

Récupère un tableau de caractères qui ne peut pas être utilisé dans le nom d’un site.

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

Retours

Char[]

Tableau de caractères qui ne peut pas être utilisé dans le nom d’un site.

Exemples

L’exemple suivant crée un site, valide le nom du site et met à jour le système de configuration.

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

Remarques

Dans un système d’exploitation Windows qui exécute le Common Language Runtime (CLR), cette méthode retourne les caractères suivants : \ ?;:@&=+$,| »<>*

S’applique à