Home >Web Front-end >HTML Tutorial >Web site error page and default access page settings_html/css_WEB-ITnose
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> <error statuscode="404" redirect="FileNotFound.htm"></error> </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></clear> <add value="default.aspx"></add> <add value="index.htm"></add> <add value="index.html"></add> <add value="index.aspx"></add> <add value="Default.htm"></add> <add value="Default.asp"></add> <add value="iisstart.htm"></add> </files> </defaultdocument> </system.webserver>