Recently we had a requirement in my project a Internet facing portal which is Architected and Designed on Microsoft Office Sharepoint Services 2007 (MOSS) to have a warm up script for Forms based authentication (FBA). We looked around the web and did not find any single solution stating how to implement this requirement hence this blog post.
Warm up scripts hit each page in a site collection thus forcing MOSS or application to cache these pages in OOB MOSS Cache or your custom cache which improves the overall performance of the site when real time users hit each page.
In a internet/intranet portal we have content enabled for authenticated users which won't be cached until those users log in to the site which will make the initial response time for those pages slow hence we need to warm up those pages as well.
This Script uses the MOSS OOB authentication web service to first authenticate the user and then hits the authenticated pages using the WebRequest and WebResponse object.
Code Snippet:
Note:Works only for MOSS Publising portal and not for other site defination however the overall concept still remians the same.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
using System.Net;
using System.Web.Security;
namespace ConsoleApplication2
{
class Program
static void Main(string[] args)
//args[0]: This is the Site Collection url, e.g.: http://pub-staging.ABCD.com
//args[1]: This is web service URL for Authentication, e.g: http://pub-staging.ABCD.com/_vti_bin/Authentication.asmx
//args[2]: This is the username
//args[3]: This is the password
//string strSiteURL = "http://pub-staging.ABCD.com";
string strSiteURL = args[0];
//
System.Net.CookieContainer cookie;
bool blnStatus = FBAAuthenticate(out cookie,args[1],args[2],args[3]);
using (SPSite site = new SPSite(strSiteURL))
foreach (SPWeb web in site.AllWebs)
Console.WriteLine("***********************************************************");
Console.WriteLine(web.Url.ToString());
if (PublishingWeb.IsPublishingWeb(web))
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
PublishingPageCollection pageColl = publishingWeb.GetPublishingPages();
//Call the web service Authentication
foreach (SPListItem listItem in publishingWeb.PagesList.Items)
if (PublishingPage.IsPublishingPage(listItem))
PublishingPage page = PublishingPage.GetPublishingPage(listItem);
try
System.Net.HttpWebRequest req =
(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(page.Uri.ToString());
req.CookieContainer = cookie;
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
using (System.IO.Stream str = res.GetResponseStream())
using (System.IO.StreamReader strReader = new System.IO.StreamReader(str))
Console.WriteLine(strReader.ReadToEnd());
strReader.Dispose();
}
catch (Exception ex)
//Handle the exception
/// <summary>
/// Sharepoint forms based authentication (FBA) web method call.
/// </summary>
/// <param name="cookieContainer">CookieContainer</param>
/// <param name="strSiteId">String</param>
/// <returns>Boolean</returns>
private static bool FBAAuthenticate(out System.Net.CookieContainer cookieContainer, string webServiceURL, string userName, string pwd)
bool blnStatus;
FBAPORTAL.Authentication auth = new FBAPORTAL.Authentication();
//auth.Url = "http://pub-staging.ABCD.com/_vti_bin/Authentication.asmx";
auth.Url = webServiceURL;
auth.CookieContainer = new System.Net.CookieContainer();
auth.AllowAutoRedirect = true;
FBAPORTAL.LoginResult loginResult = auth.Login(userName,pwd );
if (loginResult.ErrorCode == FBAPORTAL.LoginErrorCode.NoError)
blnStatus = true;
cookieContainer = auth.CookieContainer;
else
blnStatus = false;
cookieContainer = null;
return blnStatus;