This project is read-only.

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

Aug 7, 2011 at 2:02 AM

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.

Thanks in advance.


Aug 8, 2011 at 8:43 AM


I am in exactly the same situation as you are and unfortunately, continuing to hit my head against the wall on the same issue.

I have *I think* successfully changed the razor host and pageBasetype by putting in the following in the sub-app's Web.config:

        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
                <remove namespace="Microsoft.Web.Helpers" />
                <remove namespace="umbraco" />
                <remove namespace="Examine" />
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Ajax" />
                <add namespace="System.Web.Mvc.Html" />
                <add namespace="System.Web.Routing" />


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:

    <remove extension=".cshtml" />
        <remove extension=".vbhtml" />
        <remove extension=".razor" />
        <add extension=".cshtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
<add extension=".vbhtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
<add extension=".razor" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>

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 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 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.

Exception Details: System.InvalidCastException: Unable to cast object of type 'ASP._Page_admin_default_cshtml' to type 'System.Web.IHttpHandler'.

Source Error:

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.

Stack Trace:

[InvalidCastException: Unable to cast object of type 'ASP._Page_admin_default_cshtml' to type 'System.Web.IHttpHandler'.]
   System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath, VirtualPathFactoryManager virtualPathFactoryManager) +75
   System.Web.WebPages.WebPageRoute.DoPostResolveRequestCache(HttpContextBase context) +321
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270

Aug 8, 2011 at 4:07 PM
Edited Aug 8, 2011 at 9:40 PM

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.



Sep 20, 2012 at 1:13 AM

Hi guys,

Over a year later  and I'm struggling with the very same problem having hit the very same wall. Did any of you have any success?



Sep 20, 2012 at 1:34 AM

Was able to get enough functionality working to make it doable for the one site that needed it. Apart from that, decided it wasn't going to get any decent ROI so left it.

Sep 20, 2012 at 3:33 PM
Edited Sep 20, 2012 at 3:39 PM

That's terrible shame. I reckon we were all so close to getting it. I'm going to log it as an issue and see whether someone on the core team can shed some light.


Logged here. 

Feb 15, 2013 at 3:10 AM
JamesSouth wrote:
That's terrible shame. I reckon we were all so close to getting it. I'm going to log it as an issue and see whether someone on the core team can shed some light.   Logged here. 
I host my BlogEngine.NET (this blog) as a sub application under a main ASP.NET MVC 3 web application ( - 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.


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.


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

Step 2. Add below xml snipet under the <configuration /> node.
<!-- Very important, to clear the main application's settings. Else the cshtml file can't be opened. -->
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
Step 3. Make sure these dll files exist in the “bin” folder under BlogEngine.NET web root.

Now you are set to view the administrator control panels!
Feb 19, 2013 at 5:45 PM

Thanks for taking the time to jot this down. I can hardly believe this wasn't one of the steps that we tried as it is extremely obvious in retrospect.