Home > Web Front-end > HTML Tutorial > Web site error page and default access page settings_html/css_WEB-ITnose

Web site error page and default access page settings_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:55:26
Original
1307 people have browsed it

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>
Copy after login

mode description:
On specifies to enable custom errors. If defaultRedirect is not specified, users will see a generic error.

Off specifies that custom errors are disabled. This allows standard verbose errors to be displayed.

RemoteOnly Specifies that custom errors are displayed only to remote clients and ASP.NET errors are displayed to the local host. This is the default value.

The default value is RemoteOnly.


If you want to show the cause of the error programmatically, you can do this through the Page_Error event.
Another way can be achieved through Global.asax, I think this The method is more convenient, and if it can be combined with a separate more user-friendly page, it will look more comfortable

Global.asax (error log can be recorded if necessary)

 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");     }
Copy after login


Then display the error message on the ErrorPage.aspx page, or just record the log without displaying it.


2. asp.net sets the default access page priority of the site through web.config
The higher the priority is set
<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>
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template