这是我到目前为止看到的最奇怪的错误,我不知道我在这里做错了什么。
我有asp.net核心应用程序。我想将不同的layout
页面连接到Error
视图而不是默认_layout.cshtml
。以下是我遵循的步骤:
1>使用默认项目模板使用VS 2015社区创建了一个新的asp.net核心Web应用程序。
2 - ;我在_ErrorLayout.cshtml
文件夹中添加了一个新的Views\Shared
布局页面
的 _ErrorLayout.cshtml
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>My Application</title>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>
3&GT;然后我将Error.cshtml
连接到新的_ErrorLayout.cshtml
布局
的 Error.cshtml
@{
Layout = "~/Views/Shared/_ErrorLayout.cshtml";
}
<h1>Error.</h1>
<h2>An error occurred while processing your request.</h2>
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
</p>
4&GT;仅用于本地测试目的,在启动的配置方法中,我查看开发环境的/Home/Error
视图。
的 Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
//app.UseDeveloperExceptionPage();
app.UseExceptionHandler("/Home/Error");
app.UseBrowserLink();
}
}
5个用于在Home's Index方法中测试pupose throw异常 Home.cs
public class HomeController : Controller
{
public IActionResult Index()
{
throw new Exception();
}
}
现在,只要应用程序启动,它就会按预期进入错误页面。
问题
Error
视图包含不需要的文字。我只想要标题和消息。所以我删除了<h2>
以下的所有内容
修改了Error.cshtml
@{
Layout = "~/Views/Shared/_ErrorLayout.cshtml";
}
<h1>Error.</h1>
<h2>An error occurred while processing your request.</h2>
现在,如果我运行应用程序,我会收到Http 500
错误
我在IE 11中按F12并检查响应。它看起来正确,但我不知道为什么页面不呈现。以下是IE11中捕获的响应
备注
这只发生在IE 11中。谷歌浏览器在应用程序启动时显示错误页面。
如果将删除的文本放回错误视图中,则IE 11可以正常工作。