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>
  • 相关阅读:
    通过5G网络释放触觉互联网的力量
    架构师的主要职责和一些误区
    Codeforces 305E Playing with String
    hdu3949:XOR
    bzoj1923: [Sdoi2010]外星千足虫
    bzoj1013: [JSOI2008]球形空间产生器sphere
    bzoj1770: [Usaco2009 Nov]lights 灯
    一些还没有写的AC自动机题
    bzoj2553: [BeiJing2011]禁忌
    bzoj1030: [JSOI2007]文本生成器
  • 原文地址:https://www.cnblogs.com/lxhbky/p/10479363.html
Copyright © 2011-2022 走看看