Monday, September 22, 2008

Creating an ASP.Net Page and embed in SharePoint

Sometimes, we may need to create some custom logic in a page and embed in Sharepoint pages as links.
Steps for Creating an ASP.Net page and bring into SharePoint Site
Step 1: Create an ASP.Net page and write the custom code in code behind. Then build.
Step 2: Copy the *.aspx file in C:\program files\....\12\Templates\Layouts folder
Step 3: Install the dll in GAC. If not works properly, copy the dll in bin folder of virtual directory.
Step 4: Refer the aspx file as http://servername/_layouts/*.aspx
These pages will be available for all the sites in the Server.

Page Not found 404 Error Page Customization in MOSS Site

In some applications, the default 404 should be customized to another valid application page to show meaning information to the user. It's very simple to do with some steps.

The following steps should be followed to customize the 404 error message for MOSS.

1. In the MOSS server, should make a copy of
%system drive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033\sps404.html and call it as 404Page.html
2. Should create a Virtual Directory /Errors in IIS under the MOSS root web application.
3. Should create a redirect aspx page, as /Errors/404redirect.aspx. This may be SharePoint Page or Normal ASP.Net Page. This page has the custom message to be shown to the user.
4. In 404Page.html , make the following change:
STSNavigate(“/Errors/404redirect..aspx?oldUrl=" + requestedUrl)
5. create a Console Application and insert the following code and run it in MOSS server. This code sets the new file not found page in sharepoint site.

System. Uri webApplicationUri = new Uri(http://ServerName/);
SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);
webApplication.FileNotFoundPage = " 404Page.html";

v Note:
By default this is set to null. FileNotFoundPage needs to point to an html file that lives in %systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033. The file needs to be html only.