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

I am adding a custom SharePoint homepage using a feature. Everything is working fine, and the redirection is correct whenever i open the site, however the homepage does not load and i get the following error:

The dynamicmasterpagefile attribute on the page directive is not allowed in this page.

My custom home page is a SharePoint application page. if i use a simple html page (renamed to .aspx) it works fine, but i need my page to have the (DynamicMasterPageFile="~masterurl/default.master") attribute in order to be able to use some features (like dialogs popups, etc...)

any idea how to fix this?

share|improve this question

2 Answers 2

ApplicationPages are great for custom forms or for reusable features, but I wouldn't look to use it as the homepage for a site.

The standard way to create a page is grab a filestream copy of one of the standard files and save it into a document library. The code below will create a page called Home.aspx, based on the basic homepage (Default.aspx) provisioned with teamsites when the Wiki Homepage is not employed.

The key line is the GetGenericSetupPath which points to the template you want to use. In this case it uses the basic home page, but you can also use the various web part pages, or publishing pages.

SPFolder libFolder = web.GetFolder(libName);
string newFilename = "Home.aspx";
string templateFilename = "default.aspx";
string path = SPUtility.GetGenericSetupPath("TEMPLATE\\SITETEMPLATES\\STS\\");
SPFile newFile = null;
FileStream stream = new FileStream(path + templateFilename, FileMode.Open);
SPFileCollection files = libFolder.Files;
newFile = files.Add(newFilename, stream);
stream.Close();
stream.Dispose();

After the file is added you can make it the site's homepage or WelcomePage by running the following code.

web.AllowUnsafeUpdates = true;
SPFolder rootFolder = web.RootFolder;
rootFolder.WelcomePage = newFile.Url;
rootFolder.Update();
web.AllowUnsafeUpdates = false;

You can then make changes to the page, add web parts, script references, etc.

share|improve this answer

What language is your page in? SharePoint doesn't like it if you just randomly deploy your own pages with server side code in them, so that is likely what you're running into here.

If all you want is items like the dialog and such, you can simply reference the SharePoint JavaScript libraries in your own custom page; you don't need the master per say to do that.

If you hit a SharePoint site using something like Chrome and go to the developer tools, you can see all of the script files being loaded. SharePoint breaks them out into different libraries, so you'd need to reference the CORE.js along with any of the specific libraries you want.

That should allow you to utilize the OOTB SharePoint modal dialogue functions, as an example.

share|improve this answer
    
Thanks, the thing is i even didn't put my code in, just a blank application page (no code yet, just a few links using href) –  Zee99 Oct 5 '11 at 13:47
    
Your page directive itself is likely the issue I think. If you can get away with just importing the applicable libraries so you don't need to do that, you may be able to get around your issue. The only other option would be to deploy your custom aspx as a feature using Visual Studio so that SharePoint will execute it correctly. –  webdes03 Oct 5 '11 at 13:59
    
ill try to reference the JS library and see what i;ll get (my custom page is already deployed using Visual Studio and the page directives were automatically added by Visual studio). –  Zee99 Oct 5 '11 at 14:08

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.