Running BlogEngine.NET as a sub-application in an Umbraco site

I'm try to do exactly what the title of this discussion states. I have Umbraco 4.7 and BE 2.5. Umbraco works fine with or without BE as a sub-app. BE works fine on its own but as soon as I make it a sub app the .cshtml pages stop working (dashboard, extensions,
etc.) Am I doing something wrong in setting up my web.configs? I did notice that Umbraco uses its own assembly in conjunction with Razor templates, but I don't know how to revert to the default handlers(?) for .cshtml in a sub-app.

I would really appreciate some help with this. Google seems to be lacking any answers to this problem.

And then dealing with the Umbraco buildProviders by switching back to the default (as I believe that's what BE uses as it's not specified otherwise) by placing the following in the sub-app's Web.config/compilation section:

However, now it fails with i.e. "Unable to cast object of type 'ASP._Page_admin_default_cshtml' to type 'System.Web.IHttpHandler'."
which is indicative of, in ASP.NET MVC, of not having a controller. For our situation? Who knows. I've worked with Razor with MVC, but apart from Razor templates in Umbraco, and now hitting BlogEngine.net with a hammer, I've not dealt with getting razor
templates working with WebPages, so I'm getting no further on something that might be obvious to somebody who actually has put together the BlogEngine.net razor template integration.

I would love to have anybody's feedback on what can be done to get Umbraco and BE happily living together (which apart from .cshtml pages served up directly, they do.

Here's the full stack trace:

Unable to cast object of type 'ASP._Page_admin_default_cshtml' to type 'System.Web.IHttpHandler'.

Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

I don't think configuring the default Razor settings is the problem. In the case of BlogEngine the cshtml files are used as templates and not like views would be in an MVC architectured application. In an MVC application you can't request Razor script files
directly, only through a view. That's why you're seeing the casting error. BlogEngine must intercept the request for cshtml files and route the request through a Razor parser to build up the text/html response. What I'm thinking is that whatever piece of code
intercepts the request is being bypassed or ignored when BlogEngine is a sub-application. Right now I'm looking through the source code to try and find some code that would perform said function. At this point I've found the Razor Parser (or what I think might
be it) and some associated helper functions in App_Code/Helpers/RazorHelper.cs but as of yet I don't have a complete picture of the entire request/response mechanism that BlogEngine uses.

The only other reference to "razor" or "cshtml" in the code is in BlogSetting.cs From what I can tell the code in this file has a lot to do with how to handle razor and non-razor based themes but this conclusion could be wrong.

If anyone can shed some light on how BlogEngine handles requests for .cshtml files and renders HTML back to the browser would be appreciated.

I host my BlogEngine.NET (this blog) as a sub application under a main ASP.NET MVC 3 web application (zizhujy.com) - not Umbraco, but the error messages are the same as this one - , it runs well until one day I tried to enter the administrator control panel
– the unable to cast object of type 'asp._page_admin_default_cshtml' to type 'system.web.ihttphandler' error showed on page.

Finally I managed to fix this issue by myself! The steps may also be helpful to others, so I'm sharing it here. The steps with pictures are available on my
blog post.

Cause:

The error only happens when try to view the pages that associated with .cshtml files. Seems that the BlogEngine.NET application inherited the razor settings from its parent ASP.NET MVC web application.

Solution:

Step 1. Open the web.config file under the BlogEngine.NET web root folder.