Ejemplo n.º 1
0
        public static bool HandleBadConnectionStringException(Exception exception, HttpServerUtilityBase server)
        {
            if (exception is InvalidOperationException && exception.Message.Contains("ConnectionString"))
            {
                // Probably a missing connection string.
                server.Transfer(BadConnectionStringPage);
                return true;
            }

            if (exception is ArgumentException
               && (
                      exception.Message.Contains("Keyword not supported")
                      || exception.Message.Contains("Invalid value for key")
                  )
                )
            {
                // Probably a malformed connection string.
                server.Transfer(BadConnectionStringPage);
                return true;
            }

            return false;
        }
Ejemplo n.º 2
0
 public static void HandleUnhandledException(Exception exception, HttpServerUtilityBase server,
                                             bool isCustomErrorEnabled, ILog log)
 {
     if (isCustomErrorEnabled)
     {
         server.Transfer(ErrorPageLocation);
     }
     else
     {
         log.Error("Unhandled Exception trapped in Global.asax", exception);
     }
 }
Ejemplo n.º 3
0
        public void OnApplicationError(Exception exception, HttpServerUtilityBase server, ILog log, IInstallationManager installationManager)
        {
            exception = UnwrapHttpUnhandledException(exception);
            if (exception == null)
            {
                server.Transfer(ErrorPageLocation);
                return;
            }

            if (HandleDeprecatedFilePathsException(exception, server, this))
            {
                return;
            }

            LogIfCommentException(exception, log);

            if (HandleSqlException(exception, server))
            {
                return;
            }

            BlogRequest blogRequest = BlogRequest.Current;
            if (HandleRequestLocationException(exception, blogRequest, installationManager, new HttpResponseWrapper(Response)))
            {
                return;
            }

            if (HandleBadConnectionStringException(exception, server))
            {
                return;
            }

            if (exception is HttpException)
            {
                if (((HttpException)exception).GetHttpCode() == 404)
                {
                    return;
                }
            }

            bool isCustomErrorEnabled = Context == null ? false : Context.IsCustomErrorEnabled;

            HandleUnhandledException(exception, server, isCustomErrorEnabled, log);
        }
Ejemplo n.º 4
0
        public static bool HandleSqlExceptionNumber(int exceptionNumber, string exceptionMessage,
                                                    HttpServerUtilityBase server)
        {
            if (exceptionNumber == (int)SqlErrorMessage.SqlServerDoesNotExistOrAccessDenied
               ||
               (exceptionNumber == (int)SqlErrorMessage.CouldNotFindStoredProcedure &&
                exceptionMessage.Contains("'blog_GetConfig'"))
                )
            {
                // Probably a bad connection string.
                server.Transfer(BadConnectionStringPage);
                return true;
            }

            if (exceptionNumber == (int)SqlErrorMessage.LoginFailsCannotOpenDatabase
               || exceptionNumber == (int)SqlErrorMessage.LoginFailed
               || exceptionNumber == (int)SqlErrorMessage.LoginFailedInvalidUserOfTrustedConnection
               || exceptionNumber == (int)SqlErrorMessage.LoginFailedNotAssociatedWithTrustedConnection
               || exceptionNumber == (int)SqlErrorMessage.LoginFailedUserNameInvalid
                )
            {
                // Probably a bad connection string.
                server.Transfer(DatabaseLoginFailedPage);
                return true;
            }
            return false;
        }