If you host a WCSF application on IIS 7 (integrated mode), you will notice that the application throws an exception on its first request (System.Web.HttpException: Request is not available in this context).

This is because when the Application_Start method of the WebClientApplication class calls the GetConfiguration method of the WebConfigModuleInfoStore class, it requires access to the HttpContext.Request that is not yet available at this point of the application’s life cycle.

That said, I will show you how to workaround it without rebuilding the CWAB and taking advantage of Dependency Injection in just three simple steps:

  1. Copy the class named WebConfigModuleInfoStore under the project CompositeWeb into your main Web application, then rename it to WebConfigModuleInfoStoreExtended.
  2. In the method GetConfiguration paste the following code:
    private static System.Configuration.Configuration GetConfiguration(string configFilePath)
    {
        System.Configuration.Configuration configuration;
        HttpContext context = HttpContext.Current;
        if (context == null)
        {
            configuration = GetConfigurationForCustomFile(configFilePath);
        }
        else
        {
            configuration =
            WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath + "/" +
                                             configFilePath.Substring(HttpRuntime.AppDomainAppPath.Length));
        }
        return configuration;
    }

  3. In your main Web application in the Global.asax, override the AddRequiredServices and paste the following code:
    protected override void AddRequiredServices()
    {
        WebClientApplication.AddServiceIfMissing<WebConfigModuleInfoStoreExtended, IModuleInfoStore>(RootContainer);
        base.AddRequiredServices();
    }

Basically, I took inspiration from Paulo Morgado’s post to figure out how to replace the calls to the HttpRequest to use HttpRuntime.

You can find the complete code implemented in one of the quickstarts for CWAB to download from here.

I hope you can find this post helpful.

One Response to “Running WCSF on IIS 7 (integrated mode)”

  1. nobodybutca Says:

    Hi,

    Great post, currently my problem on my small wcsf site, hosted on a shared hosting, Thanks.

    And do you happend to know the solution on how to save the collapse/expand of the Navigation TreeView of the WCSF?

    I tried this link which is working on a normal asp.net page but not in WCSF. =(

    http://blog.binaryocean.com/PermaLink,guid,23808645-43b5-4e2a-afb1-53dc8da35636.aspx

    Br,

    No Body

Leave a Reply