如何在Razor网站上制作/views/shared/_layout.cshtml返回404页面

bka*_*aid 5 razor asp.net-mvc-3

我希望这个网址(/views/shared/_layout.cshtml)生成一个404响应代码并显示我的自定义404页面.它目前生成此500错误和堆栈跟踪:

异常详细信息:System.Web.HttpException:无法提供带前导下划线("_")的文件.

堆栈跟踪:[HttpException(0x80004005):无法提供带前导下划线("_")的文件.] System.Web.WebPages.WebPageRoute.GetRouteLevelMatch(String pathValue,IEnumerable 1 supportedExtensions, VirtualPathFactoryManager virtualPathFactoryManager) +291 System.Web.WebPages.WebPageRoute.MatchRequest(String pathValue, IEnumerable1 supportedExtensions,VirtualPathFactoryManager virtualPathFactoryManager)+441 System.Web.WebPages .WebPageRoute.DoPostResolveRequestCache(HttpContextBase context)+222 System.Web.WebPages.WebPageHttpModule.OnApplicationPostResolveRequestCache(Object sender,EventArgs e)+146 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+220 System.Web .HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)+120

mar*_*ind 1

确保您的Views\web.config文件中有以下设置:

<appSettings>
  <add key="webpages:Enabled" value="false" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)