private void HandleError(RewriteContext context) { // Return the status code. ContextFacade.SetStatusCode((int)context.StatusCode); // Get the error handler if there is one. IRewriteErrorHandler handler = _configuration.ErrorHandlers[(int)context.StatusCode] as IRewriteErrorHandler; if (handler != null) { try { _configuration.Logger.Debug(MessageProvider.FormatString(Message.CallingErrorHandler)); // Execute the error handler. ContextFacade.HandleError(handler); } catch (HttpException) { throw; } catch (Exception exc) { _configuration.Logger.Fatal(exc.Message, exc); throw new HttpException( (int)HttpStatusCode.InternalServerError, HttpStatusCode.InternalServerError.ToString()); } } else { throw new HttpException((int)context.StatusCode, context.StatusCode.ToString()); } }
private static void ReadErrorHandler(XmlNode node, RewriterConfiguration config) { XmlNode codeNode = node.Attributes[Constants.AttrCode]; if (codeNode == null) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrCode), node); } XmlNode typeNode = node.Attributes[Constants.AttrType]; XmlNode urlNode = node.Attributes[Constants.AttrUrl]; if (typeNode == null && urlNode == null) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrUrl), node); } IRewriteErrorHandler handler = null; if (typeNode != null) { // <error-handler code="500" url="/oops.aspx" /> handler = TypeHelper.Activate(typeNode.Value, null) as IRewriteErrorHandler; if (handler == null) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidTypeSpecified)); } } else { handler = new DefaultErrorHandler(urlNode.Value); } config.ErrorHandlers.Add(Convert.ToInt32(codeNode.Value), handler); }
private static void ReadErrorHandler(XmlNode node, IRewriterConfiguration config) { var code = node.GetRequiredAttribute(Constants.AttrCode); XmlNode typeNode = node.Attributes[Constants.AttrType]; XmlNode urlNode = node.Attributes[Constants.AttrUrl]; if (typeNode == null && urlNode == null) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrUrl), node); } IRewriteErrorHandler handler = null; if (typeNode != null) { // <error-handler code="500" url="/oops.aspx" /> handler = TypeHelper.Activate(typeNode.Value, null) as IRewriteErrorHandler; if (handler == null) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidTypeSpecified, typeNode.Value, typeof(IRewriteErrorHandler)), node); } } else { handler = new DefaultErrorHandler(urlNode.Value); } if (!int.TryParse(code, out var statusCode)) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidHttpStatusCode, code), node); } config.ErrorHandlers.Add(statusCode, handler); }
private void HandleError(IRewriteContext context) { // Return the status code. _httpContext.SetStatusCode(context.StatusCode); // Get the error handler if there is one. if (!_configuration.ErrorHandlers.ContainsKey((int)context.StatusCode)) { // No error handler for this status code? // Just throw an HttpException with the appropriate status code. throw new HttpException((int)context.StatusCode, context.StatusCode.ToString()); } IRewriteErrorHandler handler = _configuration.ErrorHandlers[(int)context.StatusCode]; try { _configuration.Logger.Debug(MessageProvider.FormatString(Message.CallingErrorHandler)); // Execute the error handler. _httpContext.HandleError(handler); } catch (HttpException) { // Any HTTP errors that result from executing the error page should be propogated. throw; } catch (Exception exc) { // Any other error should result in a 500 Internal Server Error. _configuration.Logger.Error(exc.Message, exc); HttpStatusCode serverError = HttpStatusCode.InternalServerError; throw new HttpException((int)serverError, serverError.ToString()); } }
/// <summary> /// Handles an error with the error handler. /// </summary> /// <param name="handler">The error handler to use.</param> public void HandleError(IRewriteErrorHandler handler) { handler.HandleError(HttpContext.Current); }
/// <summary> /// Mock implementation of IHttpContext.HandleError /// </summary> /// <param name="handler"></param> public void HandleError(IRewriteErrorHandler handler) { throw new NotImplementedException(); }
/// <summary> /// Handles an error with the error handler. /// </summary> /// <param name="handler">The error handler to use.</param> public void HandleError(IRewriteErrorHandler handler) { handler.HandleError(HttpContext.Current); }
/// <summary> /// Handles an error with the error handler. /// </summary> /// <param name="handler">The error handler to use.</param> public void HandleError(IRewriteErrorHandler handler) { Assert.Fail("Error! Ohe Noes!"); }
/// <summary> /// Mock implementation of IHttpContext.HandleError /// </summary> /// <param name="handler"></param> public void HandleError(IRewriteErrorHandler handler) { throw new NotImplementedException(); }