Razor视图类型不从“System.Web.WebPages.WebPage”继承(Razor v

2019-09-17 01:14发布

我有一个配置asp.net MVC应用程序中的一个问题:

[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

我想要做的步骤:

  • 移动控制器,其观点为独立的库,并把DLL加载到bin文件夹。
  • 创建虚拟文件提供商和虚拟文件汇编得到的数据:

     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; } 
  • 收藏此行到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> 
  • 当用户访问该控制器的页面被正确编译成以下类:

     public class _Page_Currency_Index_cshtml : System.Web.Mvc.WebViewPage<GridModel<CurrencyModel>> { 
  • 之后,它失败,此错误(和我所看到的 - 他是对的,输入“ASP._Page_Currency_Index_cshtml”不从“System.Web.WebPages.WebPage”继承)

我应该怎么做才能让一个HttpApplication知道这个页面应该System.Web.Mvc.WebViewPage而不是System.Web.WebPages.WebPage进行管理?

我曾试图移动浏览/ Web.Config中进入bin文件夹,但它并不能帮助。

Answer 1:

尝试添加该到AppSettingsWeb.Config

<add key="webpages:Enabled" value="false" />


文章来源: Razor view Type does not inherit from 'System.Web.WebPages.WebPage'