Paulo Morgado

.NET Development & Architecture

This Blog

Syndication

Search

Tags

News

Unit Test Today! Get Typemock Isolator!

Projects

Books

 

Visitors

Visitor Locations

Community

Email Notifications

Archives

Profile

Disclaimer

The opinions and viewpoints expressed in this site are mine and do not necessarily reflect those of Microsoft, my employer or any community that I belong to. Any code or opinions are offered as is. Products or services mentioned are purchased by me, made available to me by my employer or the manufacturer/vendor which doesn't influence my opinion in any way.

WCSF 2.0 And IIS7 Integrated Pipeline Mode

While preparing the demos for my session at TechDays Portugal 2008, I've noticed that the Web Client Software Factory 2.0 doesn't work with IIS7 in integrated pipeline mode because it's trying to access the Request property of the current HTTP Context from the HTTP Application Start "event", which is not available at this point.

This is an already known issue and you can vote to get it solved.

Meanwhile, there are two ways to work around this:

Changing the Composite Web Application Block

If you are comfortable with having your own build of this block instead of the provided strong named one, you only need to change one statement in the WebConfigModuleInfoStore class (WCSFBlocks-Feb2008\CompositeWeb\Source\CompositeWeb\Services\WebConfigModuleInfoStore.cs, line 105).

Just replace:

configuration =
    WebConfigurationManager.OpenWebConfiguration(context.Request.ApplicationPath + "/" +
                                                 configFilePath.Replace(context.Request.PhysicalApplicationPath, ""));

with:

configuration =
    WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath + "/" +
                                                 configFilePath.Substring(HttpRuntime.AppDomainAppPath.Length));

Changing the application

If you prefer to (or have to) use the provided and strong named version of the Composite Web Application Block, you can always change your application.

Just open the generated global.asax file:

<%@ Application Language="C#" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" %>

and add:

<script RunAt="server">

    private bool initialized;

    protected override void Application_Start(object sender, EventArgs e)
    {
        this.initialized = false;
    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        if (!this.initialized)
        {
            this.initialized = true;

            base.Application_Start(sender, e);
        }
    }

</script>

Published Tue, Mar 11 2008 11:06 by Paulo Morgado

Comments

# Upgrading the WCSF EventBroker Extension to WCSF 2.0@ Tuesday, March 11, 2008 7:15 PM

While preparing the demos for my session at TechDays Portugal 2008 , I've noticed some changes in the

Paulo Morgado

# Upgrading the WCSF EventBroker Extension to WCSF 2.0@ Tuesday, March 11, 2008 7:15 PM

While preparing the demos for my session at TechDays Portugal 2008 , I've noticed some changes in

Paulo Morgado

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Monday, July 07, 2008 6:05 PM

On busy sites you may need to worry about multithreading as BeginRequest is not threadsafe.

private bool initialized = false;

   protected override void Application_Start(object sender, EventArgs e)
   {
       // Override the application start so that we can call it at first Application_BeginRequest

       // this is necissary for IIS7 Integrated Pipeline because Request is not available in Application_Start
   }

   protected void Application_BeginRequest(object sender, EventArgs e)
   {
       if (System.Threading.Interlocked.CompareExchange(ref initialized, true, false))
       {
           base.Application_Start(sender, e);
       }
   }

Josh

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Monday, July 07, 2008 6:10 PM

And if that didn't work (because bool is not a reference type :( ) try this...

//0=false 1=true

   private int initialized = 0;

   protected override void Application_Start(object sender, EventArgs e)
   {
       // Override the application start so that we can call it at first Application_BeginRequest

       // this is necissary for IIS7 Integrated Pipeline because Request is not available in Application_Start
   }

   protected void Application_BeginRequest(object sender, EventArgs e)
   {
       if (System.Threading.Interlocked.Exchange(ref initialized, 1) == 0)
       {
           base.Application_Start(sender, e);
       }
   }

Josh

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Monday, July 07, 2008 6:30 PM

Thanks Josh.

Can you provide a link to that information that BeginRequest is not thread safe in integrated pipeline mode? I can't seem to find it.

Paulo Morgado

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Tuesday, October 28, 2008 6:46 AM

Also, method #2 has issues with WebClientAuthorizationModule because when it's initialized and wants to add handler for AuthorizeRequest - RootContainer is not yet initialized due to moving Application_Start to a later stage.

qualiarunner

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Monday, December 08, 2008 2:22 PM

Paulo,

Have you had any further issues with this?

Zinovate

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Monday, December 08, 2008 4:42 PM

Unfortunately, I haven’t been working with WCSF or IIS7 lately.

Paulo Morgado

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Monday, January 19, 2009 8:23 AM

Excuse me?  What does that mean?

Mike Nicol

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Monday, January 19, 2009 3:03 PM

Escuse me. Mike. I don't understand your question.

Paulo Morgado

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Monday, December 07, 2009 8:32 AM

An object with this ID already exists: Shell.

Andrey

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Monday, December 07, 2009 8:33 AM

I have  error

An object with this ID already exists: Shell.

Andrey

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Tuesday, December 08, 2009 1:59 PM

Where are you having this error? Can you provide a stack trace?

Paulo Morgado

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Thursday, December 10, 2009 3:29 AM

Hi!

I'm also having the same problem as Andrey.

It works most of the time, but sometimes an exception is thrown at the following line:

base.Application_Start(sender, e);

See stack trace below:

System.ArgumentException was unhandled by user code

 Message="An object with this ID already exists: Shell."

 Source="Microsoft.Practices.CompositeWeb"

 StackTrace:

      at Microsoft.Practices.CompositeWeb.Collections.ManagedObjectCollection`1.Build(Type typeToBuild, String idToBuild, Object item)

      at Microsoft.Practices.CompositeWeb.Collections.ManagedObjectCollection`1.AddNew(Type typeToBuild, String id)

      at Microsoft.Practices.CompositeWeb.Collections.ManagedObjectCollection`1.AddNew[TTypeToBuild](String id)

      at Microsoft.Practices.CompositeWeb.Services.ModuleLoaderService.Load(CompositionContainer rootContainer, IModuleInfo[] modulesInfo)

      at Microsoft.Practices.CompositeWeb.WebClientApplication.LoadModules()

      at Microsoft.Practices.CompositeWeb.WebClientApplication.Application_Start(Object sender, EventArgs e)

      at ASP.global_asax.Application_BeginRequest(Object sender, EventArgs e) in c:\temp\WebClient\Global.asax:line 17

      at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

      at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

 InnerException:

Regards,

Niklas

Niklas

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Thursday, December 10, 2009 5:47 AM

I haven't worked with the Web Client for a long time, but I would say that something is being registerede more than ownce. Looks like too shells are being registered.

You can:

1. Get the source from webclientguidance.codeplex.com and debug into it.

2. Get the Reflector Pro EAP (www.red-gate.com/.../viewforum.php) and debug into it.

3. Check the Web Client Guidance forums (webclientguidance.codeplex.comThread/List.aspx, webclientguidance.codeplex.comWorkItem/List.aspx)

Paulo Morgado

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Sunday, March 14, 2010 12:31 AM

Above solution of putting a check in Application_BeginRequest will not work even with the Interlocked.Exchange check. This is because Application_BeginRequest is called per request and will execute in parallel for simultaneous requests. Assume that two requests arrive at the same time. Request1 will get Interlocked.Exchange to true and enter the if loop to call  base.Application_Start. Now, say the context switches to Request2. Request2 will see Interlocked.Exchange as false and not enter the if loop. But it can continue with the request. Now, if Request2 goes ahead before base.Application_Start is called by Request1 then you may get other errors as at that time the WCSF system initialization may not have completed.

Since Application_BeginRequest is called for every request, putting a check here will slow down the application a bit. Other way is to handle this in Application_Start itself. Since WCSF requires a request object you can create a dummy request object before the base.Application_Start is called.

AMD

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Sunday, March 14, 2010 3:40 PM

Agreed. The latest version (still in development - webclientguidance.codeplex.com) doesn't seem to suffer from this.

In fact, initializadtion done on Application_Start shouldn't need an instance of HttpContext. If meeded, i should be an HTTP Module (one per worker thread).

Paulo Morgado

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Thursday, December 09, 2010 10:58 AM

Hi,

We are using Feb 2008 version of WCSF. Now, to resolve this, which build you suggest to download?

My Current Env. VS 2008 SP1, .Net Framework 3.5, IIS 7.0.

Thanks in advance.

Venky

# re: WCSF 2.0 And IIS7 Integrated Pipeline Mode@ Wednesday, December 29, 2010 4:23 AM

Have you tried to get help from webclientguidance.codeplex.com

Paulo Morgado

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: