I have a problem with configuring asp.net mvc application:
[HttpException (0x80004005): Type 'ASP._Page_Currency_Index_cshtml' does not inherit from 'System.Web.WebPages.WebPage'.]
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +11454171
System.Web.WebPages.BuildManagerWrapper.CreateInstanceOfType(String virtualPath) +347
System.Web.WebPages.VirtualPathFactoryManager.CreateInstanceOfType(String virtualPath) +239
System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath, IVirtualPathFactory virtualPathFactory) +57
System.Web.WebPages.WebPageRoute.DoPostResolveRequestCache(HttpContextBase context) +407
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270
Steps that I want to do:
- Move controllers with its views into separate library and put dll into bin folder.
Create virtual file provider and virtual file to get data from assembly:
public override Stream Open() { var resourceName = this.path; var asmName = this.assembly.GetName().Name; var manifestName = asmName + ".Views" + resourceName.Trim('~').Replace("/", "."); var resourceStream = this.assembly.GetManifestResourceStream(manifestName); return resourceStream; }
Add this lines into web.config:
<configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Helpers" /> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> <add namespace="System.Web.WebPages" /> </namespaces> </pages> </system.web.webPages.razor>
When user access this controller's page it is compiled correctly into the following class:
public class _Page_Currency_Index_cshtml : System.Web.Mvc.WebViewPage<GridModel<CurrencyModel>> {
And after that it fails with this error (and as I can see - he is right, Type 'ASP._Page_Currency_Index_cshtml' does not inherit from 'System.Web.WebPages.WebPage'.)
What should I do to let HttpApplication know that this page should be managed as System.Web.Mvc.WebViewPage instead of System.Web.WebPages.WebPage?
I have tried to move Views/Web.Config into bin folder, but it does not help.
Try adding this to the AppSettings
in Web.Config
:
<add key="webpages:Enabled" value="false" />
来源:https://stackoverflow.com/questions/10460913/razor-view-type-does-not-inherit-from-system-web-webpages-webpage