SPSite.Protocol 属性

Gets the protocol that is used by the server.

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

语法

声明
Public ReadOnly Property Protocol As String
    Get
用法
Dim instance As SPSite
Dim value As String

value = instance.Protocol
public string Protocol { get; }

属性值

类型:System.String
A string that specifies the protocol and ends with a colon (":"). The value is either "http:" or "https:", depending on the URL that is used in constructing the SPSite object.

示例

The following example is a console application that constructs an absolute URL for the default page of a child Web site in a site collection. The example assumes that https://localhost/sites/sitecollection is a valid URL for a site collection and that the collection has a child Web site named "subsite".

Note that the example's method for creating a URL is intentionally indirect. The code that builds an absolute URL for the site collection could be replaced by a single line that accesses the Url property, which returns an absolute URL. However, the example takes a longer path in order to demonstrate how properties of the SPSite object give easy access to parts of the URL.

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost/sites/sitecollection")
         Using web As SPWeb = site.OpenWeb("subsite")

            Dim absoluteUrl As String = site.Protocol + "//"
            absoluteUrl += site.HostName + ":" + site.Port.ToString()
            absoluteUrl += web.RootFolder.ServerRelativeUrl
            absoluteUrl += "default.aspx"
            Console.WriteLine(absoluteUrl)

         End Using
      End Using
      Console.ReadLine()
   End Sub
End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("https://localhost/sites/sitecollection"))
         {
            using (SPWeb web = site.OpenWeb("subsite"))
            {
               string absoluteUrl = site.Protocol + "//";
               absoluteUrl += site.HostName + ":" + site.Port.ToString();
               absoluteUrl += web.RootFolder.ServerRelativeUrl;
               absoluteUrl += "default.aspx";
               Console.WriteLine(absoluteUrl);
            }
         }
         Console.ReadLine();
      }
   }
}

另请参阅

引用

SPSite 类

SPSite 成员

Microsoft.SharePoint 命名空间

Url