SiteCollection.InvalidSiteNameCharacters 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索不能在网站名称中使用的字符数组。
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 操作系统中,此方法将返回以下字符:\?;:@&=+$,|”<>*
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈