ASP.NET08 Feb 28, 2018 ASP.NET 配置错误页1234567891011<customErrors mode="On" defaultRedirect="~/test2/404.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors>---------------------------在Application_Error中发生错误时转向另外一个页面------------------------protected void Application_Error(object sender, EventArgs e) { string errorMsg = Context.Error.Message + Environment.NewLine + Context.Error.StackTrace + "【" + DateTime.Now.ToString() + "】" + Environment.NewLine + "====================================================" + Environment.NewLine; File.AppendAllText(Server.MapPath("~/log.txt"), errorMsg); Response.Redirect("~/test2/404.htm"); } mvc中只能将静态页面放在根目录或者创建一个Error控制器 Read More cache 错误页 HttpModule