views:

182

answers:

4

I'm facing an issue that seems to be related to configuration.

I have a webapplication based on MonoRail, where we utilize the routing feature from MonoRail. On the first request after the application has started, the routing isn't initialized. To circumvent this, I have the following code in Application_OnError():

public virtual void Application_OnError()
{
    if ( // identified as routing error )
    Server.TransferRequest( Context.Request.RawUrl, false );
    return;
}

Problem beeing that on our development server (which runs server 2008 R2, with IIS 7.5 and .NET 3.5) returns a blank page without headers, but on my workstation (which runs win7, IIS 7.5 and .NET 3.5) it works fine.

What could be the cause of this? If the code in Application_OnError() throws an exception, what would be the expected output?

I have verified the following:

  • The access-log shows one entry, I'm not sure if a TransferRequest would show up as a second entry when invoked successfully
  • The application actually do some work according to my internal logs, and it doesn't die since a subsequent requests works flawlessly (because routing will be active)

Any hints on what to look for would be greatly appreciated!

+1  A: 

Is the application pool on the Server install configured to use the integrated pipeline? It needs to be in order for Server.TransferRequest to work.

From MSDN Documentation:

This method is used when running with the integrated pipeline mode in IIS 7.0 to allow request processing to be transferred from one resource type to another while executing the target request with the correct request context.

Warren
Nice suggestion, however the app pool is set as Integrated so that's not the case, sorry.
jishi
A: 
Even Mien
I have them registered in Application_OnStart() today, and I think there is a glith on the first request that triggers the application start, where RoutingModuleEx actually is invoked before the application starts (hence, not rewriting the first request). I think it only works correctly when defining routes in web.config, not in code.
jishi
I don't really recall why we used the Server.TransferRequest, but I think it was to make it transparent for the visitor, but still incoking the request through all available modules. A Response.Redirect would probably work, but this should work to since it "works on my machine"
jishi
+1  A: 

I think that there is a throw error, but you do not see it because your page is all ready on some other error and you need to capture it that way. After that you can find the real problem, because from my checks in TransferRequest can be many thinks that give error.

public virtual void Application_OnError()
{
    if ( identified as routing error )
    {
        try
        {    
            Server.TransferRequest( Context.Request.RawUrl, false );
        }
        catch(Exception x)    
        {
            LogTheError(x.ToString());
        }
    }

    return;
}
Aristos
I'll try this, thanks!
jishi
A: 

One thing you should look into is Server.ClearError(). There are some breaking changes from Win 7 and Server 2008 with the pipeline and errors.

http://mvolo.com/blogs/serverside/archive/2007/12/08/IIS-7.0-Breaking-Changes-ASP.NET-2.0-applications-Integrated-mode.aspx

Look at item #21 in the list.

Not sure if this is your problem but it seems like it might be something worth checking.

spinon
Hm, but my dev-machine is Win 7 (which works) and the stage-server is 2008 R2 (which fails). I assume these versions should be almost identical?
jishi
I am guessing that there is a change between 2008 R2 and Win 7 that might not have been caught. It might be interesting to try on a 2008 machine(non R2) and see if you still have this problem. I am guessing you probably won't.
spinon