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. How can I do that? Please help...


Kosty, you can set the welcome page via the WelcomePage property of the RootFolder of the new SPWeb that you're creating:

SPWeb web = GetYourSPWebObject();
web.RootFolder.WelcomePage = "/Pages/Landing.aspx";

If you are trying to achieve this with a page in the Layouts folder in the hive, see Redirect default.aspx or change default landing to page in _layouts folder?

You can place this code in your feature receiver to set the welcome page when the feature is activated (and to set it back when the feature is deactivated).

  • Thanks for the response. Initially there was no welcome page. Setting it up using the above mentioned method doesn't help. Seems like Welcome Page and Default Page are different. Is that so? – Kosty Feb 5 '13 at 19:44
  • Do you mean PublishingWeb.DefaultPage? "Gets and sets the Welcome page for this PublishingWeb object." msdn.microsoft.com/en-us/library/… I don't know if they are or not. You could use reflector if you really wanted to know. If this is a PublishingWeb there is code in the MSDN link showing how to set this (but it's basically the same). – RJ Cuthbertson Feb 5 '13 at 19:58
  • If the page is in the root of the SPWeb (not in the Pages library, etc.), you could set the RootFolder's welcome page to just the name of the page "Page.aspx" (no /'s). – John Chapman Feb 5 '13 at 19:59
  • The page resides under the site. I have tried these ways already. It is not working. :( – Kosty Feb 5 '13 at 20:26
  • I was able to achieve similar functionality via Feature's EventReciever. – Kosty Feb 6 '13 at 15:38

Here's the code which worked for me. I put it in Feature's Event Reciever

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";



However, my changes don't show up until I disable and then re-enable my feature. Is there a work around for this? Please let me know.

  • This is essentially the same as the code that I posted. If you have a new question, please post it as a separate thread. The sharepoint.stackexchange.com/faq provides a thorough explanation of the rules and expectations of SP-SE. Welcome to the site. – RJ Cuthbertson Feb 6 '13 at 15:50
  • Of course your changes don't show up until you re-activate your feature - you put the changes into feature activate event :) – Andrey Nov 13 '13 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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