zoukankan      html  css  js  c++  java
  • Web网站错误提示页面和默认訪问页面设置

    1、asp.net 定制简单的错误处理页面

    通常web应用程序在公布后。为了给用户一个友好界面和使用体验,都会在发生错误时跳转至一个自己定义的错误页面,而不是asp.net向用户暴露出来的具体的异常列表。
     简单的错误处理页面能够通过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>

    mode说明:
    On 指定启用自己定义错误。假设未指定 defaultRedirect,用户将看到一般性错误。


     
    Off 指定禁用自己定义错误。

    这同意显示标准的具体错误。
     
    RemoteOnly 指定仅向远程client显示自己定义错误而且向本地主机显示 ASP.NET 错误。这是默认值。
     
    默认值为 RemoteOnly。


    假设想通过编程的方式来呈现错误原因,能够通过Page_Error事件来做这件事.
     还有一种方式则能够通过Global.asax来实现。我认为这样的方式较为方便。另外假设能结合一个单独的更加友好的页面,则看来起更舒服一些
     
    Global.asax(假设须要。能够记录错误日志)

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


    再将错误信息显示在ErrorPage.aspx页面上,或者仅仅记录日志不做显示。


    2、asp.net 通过web.config设置网站默认訪问页面优先级
         设置靠前的优先级别越高
      
    <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>

  • 相关阅读:
    Navicat工具破解
    ios7开发者必知
    浏览器工作原理
    Lettcode_104_Maximum Depth of Binary Tree
    LeetCode:Balanced Binary Tree
    error: openssl/md5.h: No such file or directory
    欢迎来到Swift天地(Welcome to Swift)
    最大子阵列和
    【Cocos2d-x Lua】数据库封装类型的操作
    python于lxml应用
  • 原文地址:https://www.cnblogs.com/mthoutai/p/7394895.html
Copyright © 2011-2022 走看看