BVNetwork.NotFound.Core.Custom404Handler.CheckForException C# (CSharp) Méthode

CheckForException() private static méthode

private static CheckForException ( HttpContext context, Uri notFoundUri ) : bool
context System.Web.HttpContext
notFoundUri System.Uri
Résultat bool
        private static bool CheckForException(HttpContext context, Uri notFoundUri)
        {
            try
            {
                var exception = context.Server.GetLastError();
                if (exception != null)
                {
                    Exception innerEx = exception.GetBaseException();
                    if (innerEx is PageNotFoundException)
                    {
                        // Should be a normal 404 handler
                        Logger.Information("404 PageNotFoundException - Url: {0}", notFoundUri.ToString());
                        Logger.Debug("404 PageNotFoundException - Exception: {0}", innerEx.ToString());
                        return true;
                    }

                    // IO File not Found exceptions means the .aspx file cannot
                    // be found. We'll handle this as a standard 404 error
                    if (innerEx is FileNotFoundException)
                    {
                        Logger.Information("404 FileNotFoundException - Url: {0}", notFoundUri.ToString());
                        Logger.Debug("404 FileNotFoundException - Exception: {0}", innerEx.ToString());
                        return true;
                    }

                    // Not all exceptions we need to handle are specific exception types.
                    // We need to handle file not founds, for .aspx pages in directories
                    // that does not exists. However, an 404 error will be returned by the
                    // HttpException class.
                    HttpException httpEx = innerEx as HttpException;
                    if (httpEx != null)
                    {
                        if (httpEx.GetHttpCode() == 404)
                        {
                            Logger.Information("404 HttpException - Url: {0}", notFoundUri.ToString());
                            Logger.Debug("404 HttpException - Exception: {0}", httpEx.ToString());
                            return true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Debug("Unable to fetch 404 exception.", ex);
            }
            return false;
        }