SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am installing a sub-site in Sharepoint 2010 using PowerShell. For all the sub-sites, we have configured sharepoint to launch a particular sub-site's default.aspx page as landing page after log-in. For my use case, I want override this behavior by launching a page being created as a part of a Feature used in this sub-site. I am doind so by using following code in Feature's EventReciever.cs :

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    using (var currentWeb = properties.Feature.Parent as SPWeb)
        if (currentWeb != null)
            var root = currentWeb.RootFolder;
            if (root != null)
                root.WelcomePage = @"Management\Pages\LandingPage.aspx";



The code doesn't work until either I click on the title of the site (on top left), or enable and then re-enable the feature. Seems like code needs some kind of triggering event. Am I doing something wrong? Please help...

share|improve this question
up vote 0 down vote accepted

This code in your feature event receiver will run after the completion of your feature's activation.

From MSDN SPFeatureReceiver.FeatureActivated method:

Handles the event that is raised after a Feature is activated.


This method is called when a Feature is activated.

If you'd like to arbitrarily set your welcome page you could user PowerShell like:

$site = Get-SPSite -Identity "http://server:port/";
$web = $site.OpenWeb("WebName");
$web.RootFolder.WelcomePage = "/Path/Page.aspx";
Write-Host "Successfully updated the Welcome Page"
share|improve this answer
What is WebName in line # 2? Can you please tell me? – Kosty Feb 6 '13 at 19:32
The name of your SPWeb. Like if you created a new "Site" through the UI and called it "Accounting", the Name of the SPWeb object would be "Accounting" see:… – RJ Cuthbertson Feb 6 '13 at 21:10

Another alternative would be to intentionally wait until the user hits the site and use a control injected into additional page head that sets the value, redirects the user, and deactivates itself.

Elements file:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">

code behind for Injector.ascx:

public partial class WebPartInjector : UserControl
    protected void Page_Load(object sender, EventArgs e)
        using (new SPMonitoredScope("MySites.Branding WebPartInjector Page_Load"))
            SPWeb curWeb = SPContext.Current.Web;

                //*******DO STUFF HERE********

                        curWeb.Features.Remove(new Guid("This-is-where-you-put-the-guid-of-the-feature"));
                        //swallowing deactivation of self error 

                curWeb.AllowUnsafeUpdates = false;

            catch (Exception g)

                Logger.LogError(g, "WebPartInjector"); ;
share|improve this answer

Your Answer


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.