C#MVC5在母版页中包含自定义错误页
我们有几个C#MVC5在母版页中包含自定义错误页,c#,asp.net-mvc-5,C#,Asp.net Mvc 5,我们有几个c#mvc5应用程序。为了集中处理未处理的异常,我希望在母版页中有一个自定义错误页,并使用global.asax(在每个应用程序中)重定向到~Shared/error,以防我的任何应用程序中出现未处理的异常 已将Error.cshtml添加到母版页中的“我的共享文件夹” 将ActionResultError()添加到母版页中的SharedController.cs 制作了我的母版页的NugetPack,并将NugetPack添加到我的AppX中 已禁用添加错误筛选器(AppX)
c#mvc5
应用程序。为了集中处理未处理的异常,我希望在母版页中有一个自定义错误页,并使用global.asax
(在每个应用程序中)重定向到~Shared/error
,以防我的任何应用程序中出现未处理的异常
- 已将
添加到母版页中的“我的共享文件夹”Error.cshtml
- 将
ActionResult
添加到母版页中的Error()
SharedController.cs
- 制作了我的母版页的NugetPack,并将NugetPack添加到我的AppX中
- 已禁用添加错误筛选器(AppX)
- 在global.asax.cs(AppX)中添加了应用程序错误
- 已将web.config(AppX)中的自定义错误重定向到~/Shared/error
TIA acki在操作中输入视图的名称,如果需要母版页的名称作为第二个参数
public ActionResult Error()
{
return View("Errors");
}
在您的操作中输入视图的名称,如果您需要母版页的名称作为第二个参数
public ActionResult Error()
{
return View("Errors");
}
不工作错误。cshtml从不属于nuget包KDOESN不工作错误。cshtml从不属于nuget包
namespace ApplicationX
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
protected void Application_Error()
{
// Log error to eventlog using NLog
// ...
}
}
}
<system.web>
<customErrors mode="On" defaultRedirect="~/Shared/Error">
<error statusCode="404" redirect="~/Shared/Error" />
</customErrors>
</system.web>
System.InvalidOperationException: The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Error.cshtml
~/Views/Shared/Error.cshtml
~/Views/Shared/Masterpage/Error.cshtml
public ActionResult Error()
{
return View("Errors");
}