Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Create a Managed Path through SharePoint Object Model
    primarykey
    data
    text
    <p>This is a question for a WSS/SharePoint guru. </p> <p>Consider this scenario: I have an ASP.Net web service which links our corporate CRM system and WSS-based intranet together. What I am trying to do is provision a new WSS site collection whenever a new client is added to the CRM system. In order to make this work, I need to programmatically add the managed path to the new site collection. I know that this is possible via the Object Model, but when I try it in my own web service, it fails. Sample code extract below:</p> <pre><code> Dim _ClientSiteUrl As String = "http://myintranet/clients/sampleclient" Using _RootWeb As SPSite = New SPSite("http://myintranet") Dim _ManagedPaths As SPPrefixCollection = _RootWeb.WebApplication.Prefixes If Not (_ManagedPaths.Contains(_ClientSiteUrl)) Then _ManagedPaths.Add(_ClientSiteUrl, SPPrefixType.ExplicitInclusion) End If End Using </code> </pre> <p>This code fails with a NullReferenceException on SPUtility.ValidateFormDigest(). Research suggested that this may be due to insufficient privileges, I tried running the code within an elevated privileges block using SPSecurity.RunWithElevatedPrivileges(AddressOf AddManagedPath), where AddManagedPath is a Sub procedure containing the above code sample.</p> <p>This then fails with an InvalidOperationException, "Operation is not valid due to the current state of the object."</p> <p>Where am I going wrong?</p> <p>One workaround I have managed to do is to call out to STSADM.EXE via Process.Start(), supplying the requisite parameters, and this works.</p> <p><strong>Update:</strong> whilst developing the web service, I am running it using the built-in Visual Studio 2005 web server - what security context will this be running under? Can I change the security context by putting entries in web.config?</p> <p><strong>Update:</strong> I think the problem is definitely to do with not running the web service within the correct SharePoint security context. I decided to go with the workaround I suggested and shell out to STSADM, although to do this, the application pool identity that the web service runs under must be a member of the SharePoint administrators.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload