• 在global里捕获黄页并写入异常日志库


    可以在global文件中的application_error()中,记录用户操作中出现的异常日志

            protected void Application_Error(Object sender, EventArgs e)
        
    {
                
    try
                
    {
                    Exception exception 
    = HttpContext.Current.Server.GetLastError();
                    
    // 如果有异常,则记录异常
                    if (exception != null)
                    
    {
                        exception 
    = exception.GetBaseException();
                        log4net.ILog log 
    = log4net.LogManager.GetLogger("ErrorLogFileAppender");
        
                        
    //先注释掉,用于开发调试之用
                        
    // 保存异常记录
                        System.Text.StringBuilder errorMessage = new System.Text.StringBuilder();
                        errorMessage.Append(Environment.NewLine);
                        errorMessage.Append(
    "异常消息:");
                        errorMessage.Append(exception.Message);
                        errorMessage.Append(Environment.NewLine);
        
                        errorMessage.Append(
    "异常用户:");
                        errorMessage.Append(Environment.NewLine);
        
                        errorMessage.Append(
    "异常时间:");
                        errorMessage.Append(System.DateTime.Now.ToString());
                        errorMessage.Append(Environment.NewLine);
        
                        errorMessage.Append(
    "异常位置:");
                        errorMessage.Append(Environment.NewLine);
                        errorMessage.Append(exception.StackTrace);
                        errorMessage.Append(Environment.NewLine);

                        OperationLogBL logBl 
    = new OperationLogBL();
                        OperationLogData data 
    = new OperationLogData();
                        data.OperateDate    
    = DateTime.Now;
                        data.OperatorId        
    = CurrentUser.Info.UserID;
                        data.OperatorName    
    = CurrentUser.Info.UserName;
                        data.OperatorEnName    
    = CurrentUser.Info.UserNameEn;
                        data.TypeNo            
    = (int)Model.LogType.错误日志;
                        data.Remark            
    = errorMessage.ToString();
                        data.ModifiedId        
    = exception.Source;
                        data.ModifiedItem    
    = Request.UserHostAddress;
                        data.OldValue        
    = Request.RawUrl.ToString();
                        logBl.Add(data);
                    }
     // end if (exception != null)
                }

                
    catch (Exception ex)
                
    {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }

                      
    // 跳转至 [异常提示] 页面
                      if (ConfigurationSettings.AppSettings["EnableErrorPage"].ToLower() == "true")
                      
    {
                        
    string url = ConfigurationSettings.AppSettings["NoRightRedirect"];
                        Response.Redirect(url);
                      }

            }



    net的错误机制处理:

    。<customErrors> 配置节支持内部 <error> 标记,该标记将 HTTP 状态代码与自定义错误页关联。例如:

    <configuration>  
    <system.web>    
    <customErrors mode="RemoteOnly" defaultRedirect="/genericerror.htm">      <error statusCode="500" redirect="/error/callsupport.htm"/>      <error statusCode="404" redirect="/error/notfound.aspx"/>      
    <error statusCode="403" redirect="/error/noaccess.aspx"/>    </customErrors>  </system.web></configuration>mode   


    mode:指示自定义错误是启用、禁用还是只向远程计算机显示。值:On、Off、RemoteOnly(默认值)。 

  • 相关阅读:
    Nginx开启GZIP来压缩网页
    Nginx使用Expires增加浏览器缓存加速
    解决svn working copy locked问题
    Haproxy日志配置
    Nginx内置变量以及日志格式变量参数详解
    利用nginx来屏蔽指定的user_agent的访问以及根据user_agent做跳转
    提升linux下tcp服务器并发连接数限制
    Tomcat的SSL证书配置以及Tomcat+Nginx实现SSL配置
    配置Nginx支持SSL SNI(一个IP绑定多个证书) 以及Haproxy实现多域名证书
    Nginx限制访问速率和最大并发连接数模块--limit (防范DDOS攻击)
  • 原文地址:https://www.cnblogs.com/syveen/p/253888.html
Copyright © 2020-2023  润新知