• 网站项目异常_系统级捕获_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>
  • 相关阅读:
    [UE4]蓝图中清空变量值或设置为null
    [UE4]运行时脱离视角,进入自由视角
    [UE4]扔枪
    [UE4]反射
    为帮助保护你的安全,您的Web浏览器已经限制此文件显示可能访问您的计算机的活动内容
    [UE4]根据名字调用函数(蓝图)
    [UE4]移除UI(User Widget)并销毁
    [UE4]Return Node节点好用法
    [UE4]关于分支Sequence和条件分支的组合用法
    [UE4]隐藏对象Set Visibility
  • 原文地址:https://www.cnblogs.com/lxhbky/p/10479363.html
Copyright © 2020-2023  润新知