Пример #1
0
        private void BootstrapGlobalAsax()
        {
            _configurationRepository =
                ( IConfigurationProvider )DependencyResolver.Current.GetService(typeof(IConfigurationProvider));
            _cookieProvider = ( ICookieProvider )DependencyResolver.Current.GetService(typeof(ICookieProvider));

            _helper = ( IGlobalAsaxHelpers )DependencyResolver.Current.GetService(typeof(IGlobalAsaxHelpers));

            if (_configurationRepository == null)
            {
                throw new ArgumentNullException(nameof(IConfigurationProvider));
            }
            if (_cookieProvider == null)
            {
                throw new ArgumentNullException(nameof(ICookieProvider));
            }
            if (_helper == null)
            {
                throw new ArgumentNullException(nameof(IGlobalAsaxHelpers));
            }

            _applicationConfiguration =
                ( IApplicationConfiguration )DependencyResolver.Current.GetService(typeof(IApplicationConfiguration));

            // store the application configuration object in session cache (for the application scope) ...
            _sessionCacheProvider.SaveForApplication(_applicationConfiguration, "ApplicationConfiguration");


            _loggingFactory =
                ( ISerilogLoggingFactory )DependencyResolver.Current.GetService(typeof(ISerilogLoggingFactory));
            var loggingContext = new LoggingContextProvider();

            _logger = new SerilogErrorLogProvider(_loggingFactory, loggingContext);
        }
Пример #2
0
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            // unfortunately, this one is needed everywhere
            _helper = ( IGlobalAsaxHelpers )DependencyResolver.Current.GetService(typeof(IGlobalAsaxHelpers));

            _controllerRouteAction =
                _helper?.PopulateControllerRouteActionFromContext(ExtractContextFromSender(sender));
        }
Пример #3
0
        protected void Application_Error(object sender, EventArgs e)
        {
            #region requires this way of error handling

            try
            {
                if (_logger == null)
                {
                    _logger = DependencyResolver.Current.GetService <IErrorLogService>();
                }

                _helper        = DependencyResolver.Current.GetService <IGlobalAsaxHelpers>();
                _cookieStorage = DependencyResolver.Current.GetService <ICookieStorageService>();
            }
            catch (Exception exception)
            {
                // _logger.Error("",exception);
            }

            _controllerRouteAction = _helper.PopulateControllerRouteActionFromContext(ExtractContextFromSender(sender));

            var ex = Server.GetLastError();

            var controller = new ErrorController(_cookieStorage, null, null);
            var routeData  = new RouteData();

            var httpContext = ExtractContextFromSender(sender);

            if (ex != null)
            {
                if (ex is HttpException)
                {
                    var httpEx = ex as HttpException;

                    _logger?.LogFatal(this, "=================================================");
                    _logger?.LogFatal(this,
                                      $"{DateTime.UtcNow}: HTTP error [ {httpEx.GetHttpCode()} ] at [ {_controllerRouteAction.CurrentController}/{_controllerRouteAction.CurrentAction} ] {Environment.NewLine} [ {ex} {Environment.NewLine} ]");
                    _logger?.LogFatal(this, "");
                }
                else
                {
                    _logger?.LogFatal(this, "=================================================");
                    _logger?.LogFatal(this,
                                      $"{DateTime.UtcNow}: error '{ex.Message}' at {_controllerRouteAction.CurrentController}/{_controllerRouteAction.CurrentAction} {Environment.NewLine} [ {ex} {Environment.NewLine}  ]");
                    _logger?.LogFatal(this, "");
                }
            }

            if (_controllerRouteAction.CurrentController.Equals("Account") &&
                _controllerRouteAction.CurrentAction.Equals("Login") && (( HttpException )ex).GetHttpCode() == 500 &&
                ex.Message.Contains("anti-forgery"))
            {
                Response.Redirect(UrlConfigHelper.GetRoot() + "Account/Login", true);
            }

            httpContext.ClearError();
            httpContext.Response.Clear();
            httpContext.Response.StatusCode             = ex is HttpException ? (( HttpException )ex).GetHttpCode() : 500;
            httpContext.Response.TrySkipIisCustomErrors = true;

            routeData.Values["controller"] = "Error";
            routeData.Values["action"]     = "Error";

            controller.ViewData.Model = new ErrorViewModel(ex, _controllerRouteAction.CurrentController,
                                                           _controllerRouteAction.CurrentAction);

            (( IController )controller).Execute(new RequestContext(new HttpContextWrapper(httpContext), routeData));

            #endregion requires this way of error handling
        }