views:

120

answers:

2

I'm trying to refactor an existing asp.net-mvc web application and introduce mvc-turbine.
The application works as is, but I want to make it more pluggable and maintainable so future maintenance will be easier.

I figured I'd try to keep the refactoring steps as small as possible, so I referenced MvcTurbine, MvcTurbine.Unity and MvcTurbine.Web.
Then I made my MvcApplication in global.asax.cs look like this:

Public class MvcApplicatoin : TurbineApplication{
    static MvcApplication(){
        ServiceLocatorManager.SetLocatorProvider(() => new UnityServiceLocator());
        Application_Start();
    }
    <snip of all code that hasn't changed/>
}

I realize calling Application_Start is not how it's supposed to go, but that would keep the changes for the first step as small as possible.
When I now run, I see the code in my controller gets hit and runs correctly. Then my views are being rendered. I can step through each line, no problems there either. And then the result gets shown in the browser: gibberish.
������í½I%&/mÊ{JõJ×àt¡$Ø@ìÁÍæìiG#)«*ÊeVe]f@Ìí¼÷Þ{ï½÷Þ
etc, a whole page of that.

I didn't encounter this problem without Turbine nor did I encounter any problems in previous tests where I would introduce Turbine from the start.
Any ideas on how I can start to debug this?

+2  A: 

I'd say that somehow you're gzipping the output twice. Check out Response.Filter and HttpModules loaded after Application_Start() is called from your .cctor and after it's called from the ASP.NET engine.

Alternatively, make sure you have the Klingon fonts installed ;-)

Gonzalo
Yes, that was my first idea too. Thus I removed the reference to my compression module and removed all traces from web.config. To no avail :s
borisCallens
Cleared the cache after the changes?
Gonzalo
Restarted the application?
Gonzalo
Double check. Also removed all the bins
borisCallens
I searched my entire solution for "compres" and found a forgottan and unused (find usages didn't return a thing) HttpCompressionModule.cs which I removed. In combination with removing all references to the actual compression module I'm using (blowery.Web.HttpCompress) did the trick. Checking the response it is still gzipped. My only guess is that turbine already adds compression somewhere.
borisCallens
+1  A: 

Turbine doesn't add any compression to your application, so that's a different issue.

However, for the Application_Start method, you should not call it within your static constructor.

What you should do instead is override the Startup method and perform any logic here. However, this will not give access to the IServiceLocator you've configured for the application. If you need the IServiceLocator, override the PostServiceLocatorAcquisition method, the can use the ServiceLocator property to have access to it.

I hope this helps!

Javier Lozano
Thanks for the info. Although I hadn't looked into a better way, I figured calling the application_start was not right way. I'm trying to do the refactoring in tiny steps however, as there is quite some work involved in improving my architecture. It was one of my first big projects and now I'm kind of paying the price for sub-optimal design choices. I will use your advice along the way though :)
borisCallens