Logo SharePoint Thoughts   Downloads   About   Up to Bluedog Limited
How to Add a Custom ASP.NET Application into a Site Template
Posted on 5/6/2005 9:36 PM by pBoy

Every now and then there are circumstances where you would like to add a custom ASP.NET page to become part of a WSS or SPS site.  How do you do it?  Can you do it?  Happily, the answer is yes.

It takes some careful effort to put all the pieces together but you can incorporate your ASPX pages and custom assembly so that it looks like it’s part of an out of the box SharePoint site.  Below are the steps for doing this for a WSS site; they are very similar for an SPS Area (close enough that I’ll leave it as an exercise for the reader):

1. Create your custom ASP.NET application – add your pages and compile into an assembly (.DLL).  Very Important:  Your web pages MUST inherit from Microsoft.SharePoint.WebPartPages.WebPartPage if you want them included as part of a site.  However you can still use most of the standard ASP.NET techniques to build your pages, add custom ASP.NET controls, do data-binding, etc.

2. Create a custom site definition – the steps to do this are beyond the scope of this blog, but there have been many articles published that describe how to do this.  To customize WSS sites you’ll want to copy the contents of the STS folder in the Templates/LCID directory (where LCID is the language code of your installation, such as 1033 for US English).

3. Modify ONET.XML - add this section to the Modules section at the bottom:

<Module Name="MyCustomPageModuleName" Url="" Path="">
  <File Url="MyCustomPage.aspx" NavBarHome="False"></File>
</Module>

In this case the Url attribute of the File element is going to be the name of the ASPX page.  If you have multiple pages then you will need to create multiple File elements.

4. Modify the Module section for the template in which you want the page included.  For example to include your page when someone creates a new team site based on the Team Site template:

<Configuration ID="0" Name="Default">
 ...
 <Modules>
     <Module Name="Default"/>
     <Module Name="WebPartPopulation"/>
     <Module Name="MyCustomPageModuleName"/>
  </Modules>

Each template type has its own Configuration section; you need to customize the Modules sub-element for each template that should contain your custom page.

5. Put the assembly for your custom page in the appropriate BIN directory, i.e. C:\Inetpub\wwwroot\bin.  The location of the bin directory will vary depending on how your virtual server is configured.  Also a bin directory does not exist by default; if that’s the case then just create one and copy the assembly into it.

6. Open a command prompt and run IISRESET.  This is necessary because ONET.XML is cached by IIS so it needs to be flushed in order to pick up the changes you made.

Once you’ve completed all of these steps you can create a new site based on your updated template.  Once your site is created you can navigate to the page directly in the site.  For example if you add a page called steve.aspx to a template and create a site at http://portal/sites/monkey, you can navigate to the page at http://portal/sites/monkey/steve.aspx.

It’s an interesting technique and certainly not needed often, but it’s good to understand the required steps in case you ever need to go down that path.

pBoy

re: How to Add a Custom ASP.NET Application into a Site Template
I'm curious if this can be simplified in my case: I don't want my additions to be part of a site template, just one particular subsite.
 
I'd like to provide an easy web service to add items to a particular list without having to use the SP web services which:
 
 1) I find too expansive for my needs (I only need to add an item and get its ID back)
 
 2) I think it'll be easier to implement the Add(...) web service in terms of the SDK than the SP webservices.
 
So I wanted to simply add an ASMX with the code behind to the SP site. Do I need to do all the stuff you mention or can I just create a bin subdirectory and deploy normally?
 
Naively,
Per
Per @ 5/18/2005 9:18 AM
re: How to Add a Custom ASP.NET Application into a Site Template
Unfortunately you gotta swing the big hammer in your scenario.  Since all page requests go through the SharePoint ISAPI filter, it has to have all the pages in use registered in it's system (the database).  EVEN if you wanted to troll down an unsupported path and try to plug it in the SQL database yourself, it's unlikely you will get it everywhere you need.  I actually took a look at this just to see if it was that simple (hey, curiousity may have killed the cat...I'm a dog man).
 
Long story short, you need to go through the process outlined in the post to make it happen, even for a subsite's use only.  I think maybe the way to do it would be to create a separate site template just for those sites that require this additional functionality and use that template only on your special sub sites.
pBoy @ 5/23/2005 9:05 AM
re: How to Add a Custom ASP.NET Application into a Site Template
Need help! I have followed your instructions and it works perfectly for the default templates, i.e. whenever i create a site using one of the default templates my aspx page is present and works fine. However when i create a site using one of our custom templates my custom aspx page doesn't come up? What am I doing wrong? I had a look at the onenet.xml file and my custom template is not present within?
Tony @ 6/26/2005 8:13 PM
re: How to Add a Custom ASP.NET Application into a Site Template
Can you explain what you mean by the onet.xml file not containing your custom page?  Obviously if it isn't modified then your custom page won't show up in the site.
pBoy @ 6/28/2005 10:37 PM
re: How to Add a Custom ASP.NET Application into a Site Template
Excellent article, tested it and it worked perfectly. I've been trying to get my head around this for ages and this really helped.
 
However, my only question is...
 
If I have a several Sharepoint sub-sites, all based on the standard STS template and I add a new page to the template, when I create a new site (based on the standard template) the new page will be available on that site. However, the new page won't be available on the existing sites.
 
Is there any way to add this new page to all the existing sites based on the standard template?
Anonymous User @ 8/12/2005 7:34 AM
re: How to Add a Custom ASP.NET Application into a Site Template
Unfortunately, having this site work in sites that have already been created will not work.  The information in onet.xml is written to the database during the provisioning process.  If you modify onet.xml after the fact there's nothing that SharePoint can pick up on that allows it to reapply (and merge really) the site features.
Anonymous User @ 8/12/2005 2:42 PM
re: How to Add a Custom ASP.NET Application into a Site Template
Great Article, and just what I am looking for. Followed it step by step, except I use Portal services. I copied my .aspx file into the ...\Template\MYCUSTOMSITE folder.
 
I then proceeded to create a site and it worked fine, until i tried to access the page. Then I get a 404...? Did I copy the aspx file into the correct folder?
Anonymous User @ 8/29/2005 5:40 AM
re: How to Add a Custom ASP.NET Application into a Site Template
Hi, I was wondering how my asp.net app is called or mapped. is that during step 2 when I create the site definition?
Steven Ng @ 5/7/2008 2:02 PM
RSS feed
Microsoft Certified Master
MVP Logo
Follow me on Twitter!
Keyword Search
 
View by category
 

Disclaimer:
The contents of this site represent thoughts and opinions of the authors , not those of anyone else - such as past, present and future employers.  This a forum of the exchange of ideas centered on SharePoint technologies.  It is not a support channel.  :)

Copyright © 2004-2010 Maurice Prather, Inc. All rights reserved.