1

I am developing a SharePoint 2010 Project totaly in Visual Studio and C#.

I do not want to use SharePoint Designer and configuration via browser.

I need to set a LAYOUT page (application page) as home page on multiples sites.

Is it possible?

If not, which is the best aproach?

Important: I need to solve this situation only with c# no configuration

2

You cannot set Application pages as Welcome Page, only Site pages located either at the root web or from a Pages library.

But you can use a Redirect Page or redirection from your home page to layouts page.

Please refer to Possible to have the default landing page of my Sharepoint Site be an applicaiton page?

How to Set an Application Page as a default landing page in SharePoint 2013 web site

  • Thanks Arsalan. Your second link use 2013. Is it possible in 2010? And I need to do that all by code (no configuration). Can I set a redirection in c#? – Juan Pablo Pussacq Laborde Apr 12 '16 at 11:09
  • 1
    Yes I think the page layout is available in 2010 as well. And yes you can use C# either embed a custom web part in a default page that redirects to your application page. – Arsalan Adam Khatri Apr 12 '16 at 11:10
  • Do you have and example to set redirection using c#? – Juan Pablo Pussacq Laborde Apr 12 '16 at 11:12
  • 1
    Response.Redirect(SPContext.Current.Web.Url + "/_layouts/FolderName/ApplicationPage.aspx") – Arsalan Adam Khatri Apr 12 '16 at 11:13
  • I am sorry. That's not my question. In the link you mentioned it is shown how to configure redirection on a page and then set it as your home page. All that I need to do using c # code as it applies to many sites. – Juan Pablo Pussacq Laborde Apr 12 '16 at 11:16
1

You can create a delegate control that would check if the current page is welcome page of the site. If Yes, then it would redirect to your application page using

C#

Response.Redirect(SPContext.Current.Web.Url + "/_layouts/YourApplicationPage.aspx");

JavaScript

window.location.href = _spPageContextInfo.webAbsoluteUrl + "/_layouts/YourApplicationPage.aspx";

Otherwise there is no direct way of setting an application page as welcome page.

  • What bad news! So you're saying that there is no possibility to solve this problem without redirection? – Juan Pablo Pussacq Laborde Apr 12 '16 at 12:20
1

Inspired by Arsalan Adam Khatri's answer I found a solution:

1) First create a page to handle the redirection:

LayoutPageRedirect.aspx

<html>
<head>
<META http-equiv="refresh" content="0;URL=./_layouts/folder/HomePageCustom.aspx">
</head>
</html>

2) Then create a module to deploy this file

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="ModuleLayoutPageRedirect">
    <File Path="ModuleLayoutPageRedirect\LayoutPageRedirect.aspx" Url="LayoutPageRedirect.aspx" />
  </Module>
</Elements>

3) Then change the welcome page

SPFolder rootFolder = currentWeb.RootFolder;
string home = "LayoutPageRedirect.aspx";
rootFolder.WelcomePage = home;
rootFolder.Update();

4) Finally Test

Enter http://server/site/web

Automatically goes to:

http://server/site/web/LayoutPageRedirect.aspx

And redirected to:

http://server/site/web/_layouts/folder/HomePageCustom.aspx

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.