【发布时间】:2011-08-09 18:24:20
【问题描述】:
我有一个 asp.net 应用程序正在混合或慢慢迁移到 mvc,但是当通过路由 http://localhost:9490/razor 访问时
我收到Type 'ASP._Page_Views_diagnostics_razor_cshtml' does not inherit from 'System.Web.UI.Page'.
异常详情: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
几乎直接访问时(没有 .cshtml)
http://localhost:9490/views/diagnostics/razor
这是在我将视图或控制器文件夹添加到项目之前发生的。以前是Pages/Diagnostics/razor 和routes.MapPageRoute(null, "razor", "~/Pages/Diagnostics/razor.cshtml");
配置的路由是routes.MapPageRoute(null, "razor", "~/Views/diagnostics/razor.cshtml");
它工作正常。页面本身是一个单一变量访问之外的纯 html,以确认服务器端剃须刀代码正在触发。
@{
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>
IsPost=@IsPost
</p>
</body>
</html>
【问题讨论】:
-
你有没有想过如何做到这一点?我的意思是摆脱这个错误?
标签: asp.net asp.net-mvc