1. ASP.NET customizes a simple error handling page
Usually after a web application is released, in order to give users a friendly interface and user experience, it will jump to a customized page when an error occurs. Error page, rather than the detailed exception list that ASP.NET exposes to the user.
A simple error handling page can be set through web.config
<configuration> <system.web><customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors></system.web></configuration>
void Application_Error(object sender, EventArgs e) { Exception objErr = Server.GetLastError().GetBaseException(); string error = "发生异常页: " + Request.Url.ToString() + "<br>"; error += "异常信息: " + objErr.Message + "<br>"; Server.ClearError(); Application["error"] = error; Response.Redirect("~/ErrorPage/ErrorPage.aspx"); }
<system.webServer> <defaultDocument> <files> <clear/> <add value="default.aspx"/> <add value="index.htm"/> <add value="index.html"/> <add value="index.aspx"/> <add value="Default.htm"/> <add value="Default.asp"/> <add value="iisstart.htm"/> </files> </defaultDocument> </system.webServer>