Thursday, 21 August 2008

Community Server 2.1 SP3 with IIS 7 : "Request is not available in this context"

Unfortunately, CS 2.1 will not work out-of-the-box with IIS 7.0.  There is a small problem where the Job initialisation routine attempts to get the Application's Path  on application start-up from the current request - i.e. the request that started the application.  This will no longer work because the request has been decoupled from application start-up.

This is a simple change though... just change the ApplicationPath property getter inside Globals.cs to

static public string ApplicationPath {

            get {
                string applicationPath = "/";
                if(HttpContext.Current != null)
                    applicationPath = HttpRuntime.AppDomainAppVirtualPath;

                // Are we in an application?
                //
                if (applicationPath == "/") {
                    return string.Empty;
                } else {
                    return applicationPath;
                }
            }

        }

 

The change is simple to get the Application Path from the Http Runtime, rather than the request object. i.e. using AppDomainAppVirtualPath

Just re-compile in release mode and you're away.  Also, ensure the SP level of your CS source code is the same as the binary in your app.

Here are the version numbers and release dates for CS 2.1

  • CS 2.1 Build 2.1.60809.935 August 9, 2006             RTM
  • CS 2.1 Service Pack 1 Build 2.1.61025.2 October 30, 2006
  • CS 2.1 Service Pack 2 Build 2.1.61129.2 December 5, 2006
  • CS 2.1 Service Pack 3 Build 2.1.20416.3 April 16, 2007

thanks

k