SPVirtualServerCollection class
NOTE: This API is now obsolete.
已過時。請改用SPWebApplicationCollection類別。(在Windows SharePoint Services 2.0, SPVirtualServerCollection類別代表SPVirtualServer物件的集合及維護回溯相容性。)
Inheritance hierarchy
System.Object
Microsoft.SharePoint.Administration.SPAutoSerializingObject
Microsoft.SharePoint.SPBaseCollection
Microsoft.SharePoint.Administration.SPVirtualServerCollection
Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
<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,使用myVirtualServers[index]以 C# 或 Visual Basic.NET,其中index是索引編號集合中的伺服器中的myVirtualServers(index) 。
Examples
下列程式碼範例會逐一查看集合的部署中的虛擬伺服器擴充尚未擴充與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);
}
}
}
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.