SPVirtualServerCollection 类

请注意:此 API 现在已过时。

过时。而是使用SPWebApplicationCollection类。(在Windows SharePoint Services 2.0, SPVirtualServerCollection类表示SPVirtualServer对象的集合,并保留它是为了向后兼容性。

继承层次结构

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.SPBaseCollection
      Microsoft.SharePoint.Administration.SPVirtualServerCollection

命名空间:  Microsoft.SharePoint.Administration
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
<ObsoleteAttribute("The SPVirtualServerCollection class is deprecated.  Use an SPWebApplicationCollection instead.",  _
    False)> _
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
Public NotInheritable Class SPVirtualServerCollection _
    Inherits SPBaseCollection
用法
Dim instance As SPVirtualServerCollection
[ObsoleteAttribute("The SPVirtualServerCollection class is deprecated.  Use an SPWebApplicationCollection instead.", 
    false)]
[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel = true)]
public sealed class SPVirtualServerCollection : SPBaseCollection

备注

使用SPGlobalAdmin类的VirtualServers属性返回所有虚拟服务器的部署中的Microsoft SharePoint Foundation。

若要创建管理的虚拟服务器,请使用SPGlobalAdmin类的CreateAdminVirtualServer方法。若要扩展虚拟服务器,请使用SPGlobalAdmin类的ExtendVirtualServer方法之一。

使用索引器从集合中返回单个虚拟服务器。例如,如果该集合分配给名为myVirtualServers的变量中,使用在 C# myVirtualServers[index]或myVirtualServers(index)在 Visual Basic.NET 中, index所在的服务器集合中的索引号。

示例

下面的代码示例循环访问该集合的虚拟服务器在部署和扩展不使用SharePoint Foundation已扩展的虚拟服务器分别创建顶级网站。

本示例假定存在的.cs 或.vb 文件中管理格式摘要。有关安全验证的信息,请参阅安全验证和更新数据进行公告

[Visual Basic .NET]
Dim globalAdmin As New SPGlobalAdmin()
Dim vServers As SPVirtualServerCollection = globalAdmin.VirtualServers
Dim i As Integer

For i = 0 To vServers.Count - 1

    If vServers(i).State = SPVirtualServerState.NeedExtend Then

        Dim uri As New System.Uri(vServers(i).Url.ToString())

        Try

            Dim newSPServer As SPVirtualServer = globalAdmin.ExtendVirtualServer( _
                "Database_Server", _
                "Database_Name" + i.ToString(), _
                Nothing, Nothing, uri, False, "StsAppPool1", False, _
                Nothing, Nothing)

            Dim sites As SPSiteCollection = newSPServer.Sites

            sites.Add(newSPServer.Url.ToString(), "DOMAIN\User_Alias", "Email_Address")

            Catch ex As System.Exception

                Response.Write(ex.Message + ControlChars.Lf + ControlChars.Lf + ex.StackTrace)

        End Try

    End If

Next i
[C#]
SPGlobalAdmin globalAdmin = new SPGlobalAdmin();
SPVirtualServerCollection vServers = globalAdmin.VirtualServers;

for (int i=0; i < vServers.Count; i++)
{

    if (vServers[i].State == SPVirtualServerState.NeedExtend)
    {
        System.Uri uri =  new System.Uri(vServers[i].Url.ToString() );

        try
        {
            SPVirtualServer newSPServer = globalAdmin.ExtendVirtualServer(
                "Database_Server",
                "Database_Name" + i.ToString(), 
                null, null, uri, false, "StsAppPool1", false, null, null);

            SPSiteCollection sites = newSPServer.Sites;

            sites.Add(newSPServer.Url.ToString(),"DOMAIN\\User_Alias","Email_Address");
        }

        catch (System.Exception ex)
        {
             Response.Write(ex.Message + "\n\n" + ex.StackTrace);
        }
    }
}

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

SPVirtualServerCollection 成员

Microsoft.SharePoint.Administration 命名空间