Tuesday, July 29, 2008

How to create your own custom 404 error page and handle redirect in SharePoint 2007 (MOSS)?

People alway ask how to use their own 404 file not found error page vs. the generic one from IE in MOSS environment. The following example catches the 404 error and sends users to a redirect page.

Here's the steps:

  1. In your MOSS server, make a copy of
    %systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033\sps404.html
    and call it my404.html
  2. Create a Virtual Directory in IIS under your MOSS root web application. For example /errors
  3. Create your own redirect aspx page, for example /errors/my404redirect.aspx and code your redirect logic in there. This is a normal asp.net page.
  4. In my404.html, make the following change:

    STSNavigate("/errors/my404redirect.aspx?oldUrl=" + requestedUrl);
  5. Create a Console Application and insert the following code and run it in MOSS server

System.Uri webApplicationUri = new Uri(http://MyMOSSServer/);
SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);
webApplication.FileNotFoundPage = "my404.html"; //*note
webApplication.Update();

*Note: By default this is set to null. FileNotFoundPage needs to point to a 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.

6. Now when you browse to a page that doesn't exist, you should expect to be brought to the redirected page.

*Another note:
In IE there's a "Show friendly HTTP error messages" setting which is ON by default in Internet Options->Advanced. With this setting on, sometimes your custom error page is not displayed. In order to override this setting, both my404.html and /errors/my404redirect.aspx from the above steps need to be larger than 512 bytes in size. Refer to the following KB about this setting: http://support.microsoft.com/kb/218155
* This seems to be working within a site collection context only, i.e. http://MyMOSSServer/sites/siteA if sites is a wildcard inclusion managed path and siteA doesn't exist in MOSS then this URL will NOT trigger the custom 404 error page set to SPWebApplication.FileNotFoundPage property.

Also look at SharePoint Smart 404 Feature in codeplex
http://www.codeplex.com/sharepointsmart404
It will give you advanced features

Tuesday, July 15, 2008

How to remove a bad webpart from a page?

Previously, I added a poorly written webpart to my default.aspx page. The consequence of this action is that you aren't able anymore to load the page. In this case, the only thing you have to do is to remove the webpart. Removing the webpart in the webpart gallery doesn't solve this.
Resolution:
Append ?Contents=1 to the webpart page's URL to display the Webpart Maintenance Page. On that page you can delete the malefactor.
Example: http://moss/default.aspx?contents=1

Monday, July 14, 2008

SSL on selective pages in MOSS

If you want to apply SSL on some selective pages on moss site. When you obtained the certificate and assigned the certificate to the site. when tried to browse the site You will got the error msg: that site has to be browsed using Https:// When try to browse the site I got page not found error.

One possible solution is to untick the Require secure channel (SSL) option in IIS, and manually forcing a SSL using HTTP Module.

public class HttpModule:IHttpModule
{
public void Dispose()
{
//dispose function required to declare for HttpModule class
}
public void Init(System.Web.HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
RedirectSSL(System.Web.HttpContext.Current.Request.Url.PathAndQuery);
}
public void RedirectSSL(string pageURL)
{
//get the collection of the pages requiring SSL and not requiring SSL
//check for the current page exists in the group of pages requiring SSL
//if page is found in ssl group then redirect using https:// otherwise redirect with http://
bool found = false;
string sslPages = System.Configuration.ConfigurationSettings.AppSettings["SSLPages"];
char[] separator;
separator = new char[] { ',' };
string[] pages;
pages= sslPages.Split(separator);
for (int i = 0; i < pages.Length; i++)
{
if (pageURL.Contains(pages[i]))
{
found = true;
break;
}
}
if (found)
{
if (System.Web.HttpContext.Current.Request.Url.Scheme.ToString() == "http")
{
string sURL = System.Web.HttpContext.Current.Request.Url.ToString();
sURL = sURL.Replace("http://", "https://");
System.Web.HttpContext.Current.Response.Redirect(sURL);
}
}
else
{
if (System.Web.HttpContext.Current.Request.Url.Scheme.ToString() == "https")
{
string sURL = System.Web.HttpContext.Current.Request.Url.ToString();
sURL = sURL.Replace("https://", "http://");
System.Web.HttpContext.Current.Response.Redirect(sURL);
}
}
}
}

Tuesday, June 24, 2008

Deleting SSP now Marked unprovisioning

We want to delete the SSP and in the Central Admin, When clicked the delete button and the databases associated.
It has been running for a while and doesn't seem to be doing anything and it is marked (unprovisioning)

Solution:
Run Command
stsadm -o deletessp -title SharedServicesName -force

Monday, June 23, 2008

Visual Studio 2008 extensions for WSS 3.0 v1.2 and other resources

The new version of the Visual Studio extensions for Windows SharePoint Services 3.0 were announced: it’s now finally here, a version compatible with Visual Studio 2008. This version brings the same functionalities as v1.1 for Visual Studio 2005, among others:Full Debugging with Microsoft Office SharePoint Server

  • Support for C# and VB.NET
  • Templates for Web Part, Team Site, List Definition, Field Control, Content Type, Event Handler and more.
  • Web Solution Package (WSP) Editor
  • Solution Generator creates Site Definition projects from an existing site
    Check out my Resources page for the download link.

Now that I’m doing this post, it’s worth mentioning the latest additions to my SharePoint Resources page:

  • SharePoint 2007 Shared Services Provider User Profile Importer
    SharePoint Content Deployment Wizard -
  • http://www.codeplex.com/SPDeploymentWizard
    This tool by Chris O'Brien helps you export sites, lists, etc using .cmp files (Content Migration Package).
  • WSS3 Workflow Designers
  • SmartPart for SharePoint
    The SharePoint web part which can host any ASP.NET web user control. Create your web parts without writing code! – Now with support for ASP.NET Ajax.
  • STSDEV
    STSDEV is a proof-of-concept utility application which demonstrates how to generate Visual Studio project files and solution files to facilitate the development and deployment of templates and components for the SharePoint 2007 platform.
  • SharePoint SUSHI
    (that’s a cool name as I love sushi!)SUSHI is a powerful, user-friendly SharePoint application enabling you to accomplish common SharePoint administrative and development tasks. You can think of SUSHI as a Swiss army knife for SharePoint.
  • SharePoint SmartTemplates for Visual Studio
    Another project by Jan Tielens, already famous with the creation of the SmartPart (see above).

Wednesday, June 4, 2008

How can we display attachments links of Custom List in dataview

I Created a custom list with attachment and displayed it in page using DataView but I didn't find any field of custom list to use it. Only I find 3 attributes
  1. Attachments: contains attachment folder
  2. FileRef: contains the document items FileRef column value
  3. FileDirRef: contains relative path folder
I find only way to list these attachments create a custom server control to display them and pass folder url to this control, we will generate this folder from previous attributes:

Add a custom server control like this in dataview xslt :
<spcontrol:attachment runat="server" id="attachmentLsts" path="/{@FileDirRef}/Attachments/{@Attachments}" />

this control will read path of attachment and will display list of attachment links.

Monday, June 2, 2008

Sharepoint Logging Spy

A MOSS 2007 utility to allow real time diagnostics of multiple servers in a sharepoint farm using a single console view.

To download go to url:
http://www.codeplex.com/sharepointloggingspy