ASP._page_views_diagnostics_ <page> _cshtml is not inherited from System.web.ui.page

I have an asp.net application that moves or moves slowly in mvc, but when accessed via routing http://localhost:9490/razor

I get Type 'ASP._Page_Views_diagnostics_razor_cshtml' does not inherit from 'System.Web.UI.Page'.

Exception Details: System.Web.HttpException: Type 'ASP._Page_Views_diagnostics_razor_cshtml' does not inherit from 'System.Web.UI.Page'.

 [HttpException (0x80004005): Type 'ASP._Page_Views_diagnostics_razor_cshtml' does not inherit from 'System.Web.UI.Page'.] System.Web.UI.Util.CheckAssignableType(Type baseType, Type type) +8864436 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +75 System.Web.Routing.PageRouteHandler.GetHttpHandler(RequestContext requestContext) +138 System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +8911880 System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +86 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 

When accessed almost directly (without .cshtml)

http://localhost:9490/views/diagnostics/razor

this happened before I added the views or controllers folder to the project. previously it was Pages/Diagnostics/razor with routes.MapPageRoute(null, "razor", "~/Pages/Diagnostics/razor.cshtml");

Route configuration - routes.MapPageRoute(null, "razor", "~/Views/diagnostics/razor.cshtml");

It works great. the page itself is pure html outside of a single variable access to confirm the razor code on the server side.

  @{ Layout = null; Page.Title = "Razor test"; } <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <p>Razor rendering success</p> <p> [email protected] </p> </body> </html> 
+4
source share
2 answers

I could be here :), but ... why do you use "MapPageRoute" in an MVC application, I believe this is for a web form application. Use a controller, and then MapRoute to your controller, to then go to your view. Nothing in the views folder should be directly addressable, in fact there is an entry in your web.config to specifically try to prevent this.

0
source

I suggest using WebPageRouteHandler, which you can get through the NuGet system. In response to Adam's comment, you get the ability to route a more complex URL, such as those used by Backbone.js when accessing your RESTful server. It would be ridiculous to create a separate folder for each possible id in the database. You also get the ability to organize your files in a different way than the way you structure your URLs.

0
source

All Articles