No current context when creating a sharepoint site

800 views Asked by At

I've added a feature to my onet.xml file which gets activated whenever a site gets created. However, that feature needs to know the url of the site being created. I thought I could figure that out from the current SPContext within the activation event of the feature, but when I created the site I got a null reference on SPContext.Current.

Is that to be expected, or have I done something wrong? If that is the case, does anyone have any suggestions how I can dynamically learn the URL of the site being created?

Thanks

1

There are 1 answers

0
ArjanP On

It seems like you have created a feature receiver? They don't use SPContext but find the site they have been activated on through the properties, like so:

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        using (SPWeb web = properties.Feature.Parent as SPWeb)
        {...}
    }