Tuesday, July 29, 2008

SharePoint 2007 File Not Found Problem

Many People faced File Not Found Problem When they deployed SharePoint 2007 Site. When I investigated this problem found many common reasons.
  1. Declare physical folder with same name with sharepoint virtual folders.
  2. Missing deploying physical files features, delegate controls, user controls, etc.
  3. Didn't give a physical files suitable permissions.
  4. Missing deploying custom templates.
  5. Didn't publish content files masterpages, layouts, pages, stylesheets.
    Note: To discover this problem:
    a. Change Master page from sitesettings to standard masterpage
    b. If same error already exists republish layout.[checkout, checkin, publish layout]
    c. If same error already exists validate existing physical controls, refrence dlls.
    d. If error doesn't exists when you changed master page use your masterpage do same b,c with master page.
  6. Didn't deploy dependence files or sdks (refrence files of your dlls)

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);
}
}
}
}