Monday, September 5, 2011

Fixing the The virtual path '/test/currentcontext.dummy' maps to another application, which is not allowed

We have recently integrated Spring.NET in an MVC3 application.  In one of my previous post, I have already documented the detailed process of integrating Spring.NET with MVC3 application.  Spring.NET is really helpful when it comes to writing Modular, Testable code.  I totally recommend Spring.NET as Dependency Injection framework of choice!

We did a fresh deployment of our application on a new server.  On this computer, when we tried to access any of the pages of our application we got an error which looked like

Virtual Path Maps to Another Application, is not allowed
That was not very encouraging.  How can an application that was working correctly on all other servers stared giving exceptions for this particular server?

We tried to find out what were the differences between the other server and this new server.  We narrowed it down to one very interesting difference,  we used to deploy our project as a website in IIS on all other server.  While on the server that was giving us exceptions, we deployed our application as a virtual directory under the default website.  This very curious difference was giving us exceptions while initializing the spring context.

I Googled a little and found out that this is a known issue which has been reported here and here.

The workaround to this issue was simple enough, we just have to give a name the spring context in web.config

Would any random name work?  Do we have to follow some convention?

Our Spring.NET section in web.config file looked like
By now it should be clear that, we have to add a name attribute to node. But the question is, what value should it hold?

The answer is pretty simple, the Spring.NET context should be named after the virtual directory under which the application is deployed.  For example, if the virtual directory under which the application is deployed is called springmvc.  The updated web.config should look like

This did the trick! After making this change we were able to browse all pages in our application and Spring.NET integration with MVC3 application was working well!

Small issues like these have very simple solutions but, one might end up spending quite some time before finding a satisfactory solution.  I decided to document my finding for the benefit of the community!
Have some Fun!