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