zoukankan      html  css  js  c++  java
  • 网站项目异常_系统级捕获_404页面跳转_初步认识

    前言:本人对异常的捕获是个初学者,今天刚有所接触,做个简要记录,以后会逐步完善,不足之处请批评指正:

    项目中使用C#代码直接抛出一个异常:

     throw new ArgumentException("错误的压缩级别");

    A-代码捕捉异常处理:.net Web项目,Global项目启动页,项目异常处理代码:

    protected void Application_Error(object sender, EventArgs e)
            {
                if (this.Request.FilePath == "/")
                {
                    this.Server.ClearError();
                    return;
                }
                Exception error = this.Server.GetLastError();
                Exception exception = error.InnerException ?? error;
                if (exception is HttpException)
                {
                    if ((exception as HttpException).GetHttpCode() == HttpStatusCode.NotFound.GetValue())
                    {
                        return;
                    }
                }
                _Log.Error("
    Client IP:" + this.Request.UserHostAddress + "
    Error Page:" + this.Request.Url, exception);
                HttpContext context = this.Context;
                string userName = context.User == null ? "未登录用户" : context.User.Identity.Name;
                string referrer = Request.UrlReferrer == null ? string.Empty : this.Request.UrlReferrer.AbsoluteUri;
                //this.Context.Items.Add("exception", exception);// <customErrors redirectMode="ResponseRewrite" defaultRedirect="~/404.html" mode="On">
            }

    B:配置文件项目异常404跳转处理:.net Web项目,web.config配置异常捕获:

     <httpErrors>
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" prefixLanguageFilePath="" path="/404.html" responseMode="ExecuteURL" />
          <error statusCode="404" path="/404.html" responseMode="ExecuteURL" subStatusCode="1" />
          <error statusCode="404" path="/fr/404.html" responseMode="ExecuteURL" subStatusCode="2" />
          <error statusCode="404" path="/es/404.html" responseMode="ExecuteURL" subStatusCode="3" />
          <error statusCode="404" path="/ja/404.html" responseMode="ExecuteURL" subStatusCode="4" />
          <error statusCode="404" path="/ar/404.html" responseMode="ExecuteURL" subStatusCode="5" />
          <error statusCode="404" path="/de/404.html" responseMode="ExecuteURL" subStatusCode="6" />
          <error statusCode="404" path="/it/404.html" responseMode="ExecuteURL" subStatusCode="7" />
        </httpErrors>
  • 相关阅读:
    搭建MHA问题汇总
    NOIP2009 靶形数独
    get_mysql_conn_info.py
    NOIP 2005 篝火晚会
    MySQL启动关闭添加到 /etc/init.d/mysqld
    noip2002 矩形覆盖
    get_slave_status.py
    [JSOI2008]魔兽地图
    MySQL数据导出导入任务脚本
    8.30 牛客OI赛制测试赛1 F题 子序列
  • 原文地址:https://www.cnblogs.com/lxhbky/p/10479363.html
Copyright © 2011-2022 走看看