SPSite constructor (String, SPUserToken)

Initializes a new instance of the SPSite class based on the specified absolute URL and user token.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Sub New ( _
    requestUrl As String, _
    userToken As SPUserToken _
)
'Usage
Dim requestUrl As String
Dim userToken As SPUserToken

Dim instance As New SPSite(requestUrl, _
    userToken)
public SPSite(
    string requestUrl,
    SPUserToken userToken
)

Parameters

  • requestUrl
    Type: System.String

    A string that specifies the absolute URL for the site collection.

Remarks

SPSite objects that are created with a user token run in the context of the specified user. It is not possible to change the user context of an SPSite object once it has been created. Switching users requires creating a new SPSite object.

The user token is transferable across site collections, but not across identity management systems. For example, pluggable membership and role providers that are making a request must match the provider on the resource side.

Use the UserToken property to get the user token that is associated with any SPUser object, not just the current user. If the requested user is not the current user, SharePoint Foundation builds the token from the security ID (SID) of the user and gets the group membership information using the authorization object model (see Authorization, users, groups, and the object model in SharePoint 2013).

Examples

The following code example returns the site collection located at http://Server_Name/sites/Site_Name/Subsite_Name with a specified user token.

Using oSiteCollection As New SPSite("http://Server_Name/sites/Site_Name/Subsite_Name/default.aspx", bUserToken)
    ...
End Using
using(SPSite oSiteCollection = new SPSite("http://Server_Name/sites/Site_Name/Subsite_Name/default.aspx", bUserToken))
{
   ...
}

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

See also

Reference

SPSite class

SPSite members

SPSite overload

Microsoft.SharePoint namespace