我必须关注web.config中的httpErrors部分:
<httpErrors errorMode="Custom" existingResponse="Replace" defaultPath="/ErrorPages/500.html" defaultResponseMode="File">
<clear/>
<error statusCode="400" path="/ErrorPages/400.html" responseMode="ExecuteURL"/>
<error statusCode="401" path="/ErrorPages/401.html" responseMode="ExecuteURL"/>
<error statusCode="403" path="/ErrorPages/403.html" responseMode="ExecuteURL"/>
<error statusCode="404" path="/ErrorPages/404.html" responseMode="ExecuteURL"/>
<error statusCode="500" subStatusCode="-1" path="/ErrorPages/500.html" responseMode="ExecuteURL"/>
</httpErrors>
这非常有效,除非在预应用程序启动方法或application_start方法中抛出异常,否则会显示默认的iis错误页面。
Server Error in '/' Application.
hello
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: hello
Source Error:
Line 67: void IHttpModule.Init(HttpApplication context)
Line 68: {
Line 69: throw new InvalidOperationException("hello");
Line 70: context.BeginRequest += (sender, _) =>
Line 71: {
Source File: Line: 69
Stack Trace:
[InvalidOperationException: hello]
DryIoc.Web.DryIocHttpModule.System.Web.IHttpModule.Init(HttpApplication context) in \DryIoc\Web\DryIocWeb.cs:69
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +536
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): hello]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9963856
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1637.0
即使在启动时抛出异常,我怎样才能获得自定义错误页面?