예제 #1
0
        protected void Application_Error(object sender, EventArgs e)
        {
            ErrorHandlerBusiness buss      = new ErrorHandlerBusiness();
            Exception            exception = HttpContext.Current.Error;

            var err = Server.GetLastError();

            if (err != null)
            {
                if (exception.GetType() == typeof(HttpException)) //It's an Http Exception
                {
                    var    statusCode = ((HttpException)exception).GetHttpCode();
                    var    page       = HttpContext.Current.Request.Url.ToString();
                    string userName   = "******";
                    if (Session["UserName"] != null)
                    {
                        userName = HttpContext.Current.Session["UserName"].ToString();
                        //userName = string.IsNullOrEmpty(Session["UserName"].ToString()) ? "" : Session["UserName"].ToString();
                    }
                    string ipAddress = ApplicationUtilities.GetIP();
                    var    id        = buss.LogError(err, page, userName, ipAddress);
                    switch (statusCode)
                    {
                    //case 400:
                    //    routeData.Values.Add("status", "400 - Bad Request");
                    //    break;
                    //case 401:
                    //    routeData.Values.Add("status", "401 - Access Denied");
                    //    break;
                    case 403:
                        break;

                    case 404:
                        break;

                    default:
                        //routeData.Values.Add("status", "500 - Internal Server Error");
                        HttpContext.Current.Response.Redirect("/Error/Index?Id=" + id);
                        break;
                    }
                }
            }
        }
예제 #2
0
        protected void Application_Error(object sender, EventArgs e)
        {
            bool customRedirect = true;

            if (ConfigurationManager.AppSettings["CustomRedirect"] != null && ConfigurationManager.AppSettings["CustomRedirect"].ToString().ToLower() == "false")
            {
                customRedirect = false;
            }
            ErrorHandlerBusiness buss      = new ErrorHandlerBusiness();
            Exception            exception = HttpContext.Current.Error;
            var Session = HttpContext.Current.Session;
            var err     = Server.GetLastError();

            if (err != null)
            {
                System.Diagnostics.Debug.WriteLine(exception.GetType());
                if (exception.GetType() == typeof(HttpException) || exception.GetType() == typeof(NullReferenceException) || exception.GetType() == typeof(HttpAntiForgeryException) || exception.GetType() == typeof(ArgumentNullException)) //It's an Http Exception
                {
                    int statusCode = 0;
                    if (exception.GetType() == typeof(HttpException))
                    {
                        statusCode = ((HttpException)exception).GetHttpCode();
                    }
                    var    page     = HttpContext.Current.Request.Url.ToString();
                    string userName = "******";
                    if (Session != null && Session["UserName"] != null)
                    {
                        userName = HttpContext.Current.Session["UserName"].ToString();
                        //userName = string.IsNullOrEmpty(Session["UserName"].ToString()) ? "" : Session["UserName"].ToString();
                    }
                    else
                    {
                        userName = "******";
                    }
                    string ipAddress = ApplicationUtilities.GetIP();
                    var    id        = buss.LogError(err, page, userName, ipAddress);
                    switch (statusCode)
                    {
                    //case 400:
                    //    routeData.Values.Add("status", "400 - Bad Request");
                    //    break;
                    //case 401:
                    //    routeData.Values.Add("status", "401 - Access Denied");
                    //    break;
                    case 403:
                        break;

                    case 404:
                        break;

                    default:
                        //routeData.Values.Add("status", "500 - Internal Server Error");
                        if (customRedirect)
                        {
                            HttpContext.Current.Response.Redirect("/Error/Index?Id=" + id);
                        }
                        break;
                    }
                }
            }
        }