Session State was not kept in a web farm


One of the ways to replicate content from a Web Server in an IIS 6 Web Farm to other servers in the farm is to use IISMT tool.
IISMT is a migration tool but it can also be used to "migrate" copy content and metabase configuration from IIS 6 to another IIS 6 server.

On a platform where this method was used (with ASP.NET 2.0), we encountered an issue: session was not kept while machineKey section in config file was well configured. The issue appeared with State Server as well as SQL Server.

In order to check that did not come from application, we reproed the problem by adding the two following files in ASP.NET application folder:
DebugSession.aspx which contains:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="DebugSession.aspx.cs" Inherits="_DebugSession" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Session</title>
</head>
<body>
<form id="form1" runat="server">
<div>
 </div>
</form>
</body>
</html>


and DebugSession.aspx.cs which contains:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _DebugSession : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
if (Session["now"] == null) Session["now"] = string.Empty;
Session["before"] = Session["now"];
Session["now"] = Guid.NewGuid().ToString();

Response.Write("<table><tr><td>Key</td><td>Value</td></tr>");
Response.Write(string.Format("<tr><td>Session ID</td><td>{0}</td></tr>", Session.SessionID));

foreach (string key in Session.Keys)
Response.Write(string.Format("<tr><td>{0}</td><td>{1}</td></tr>", key, Session[key]));

Response.Write("</table>");
}
}


Calling this DebugSession.aspx and refreshing it showed that session variables were definetly different on both servers (there were 2 in the farm).

By investigating further we found the issue came from the site having a different ID on the two servers.
One was at /LM/W3SVC/1, the other one was /LM/W3SVC/2 because that's the way IISMT copies configuration by default, except when you add the following command arguments: "/siteID replace"
So we deleted the Web Site on the second server and recreated it with the IISMT command line ended by /siteID replace

Please check IISMT /? for further details.

Skip to main content