Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How do I get an SPSite object from the SPWebEventProperties object passed into the SPWebEventReceiver.WebProvisioned method?

public override void WebProvisioned(SPWebEventProperties properties)
share|improve this question
    
Never mind. It was silly. SPSite site = new SPSite(properties.SiteId); –  Roxanne May 11 '11 at 18:36
add comment

2 Answers

up vote 4 down vote accepted

There is no need to create a new SPSite object. Instead use:

properties.Web.Site
share|improve this answer
add comment

This MSDN article Security Best Practices for Developers in SharePoint 2010 recommends against constructing SPSite objects using a Guid.

Construct SPSite Objects Safely

The Microsoft.SharePoint.SPSite constructor is prone to the following two problems:

New SPSite objects can be constructed by using a fully qualified domain name, for example http://contoso1.example.com. If this domain name is different from the current request context, it can lead to a cross-domain security issue.

New SPSite objects can be constructed by using a site identifier (ID) and optional user token, but without a fully qualified URL or Microsoft.SharePoint.Administration.SPUrlZone enumeration. If the current request context is not the Default zone, this can bypass web application policy.

It would be safer to use

properties.Web.Site

as advised by Anders

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.