Created
April 19, 2017 13:54
-
-
Save theuntitled/81439a798cf26cdaabc8896a98f39425 to your computer and use it in GitHub Desktop.
ASP.NET MVC error page containing the ELMAH error id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Web; | |
| using Elmah; | |
| namespace Project | |
| { | |
| /// <summary> | |
| /// A custom implementation of the elamh provided <see cref="SqlErrorLog" />. | |
| /// </summary> | |
| public class CustomSqlErrorLog : SqlErrorLog | |
| { | |
| /// <summary> | |
| /// The key to access the errors from the HttpContext.Current.Items. | |
| /// </summary> | |
| public const string HttpContextItemKey = "ELMAH.Errors"; | |
| /// <summary> | |
| /// Initializes a new instance of the <see cref="SqlErrorLog" /> class using a dictionary of configured settings. | |
| /// </summary> | |
| /// <param name="config">The settings dictionary.</param> | |
| public CustomSqlErrorLog(IDictionary config) : base(config) | |
| { | |
| } | |
| /// <summary> | |
| /// Initializes a new instance of the <see cref="SqlErrorLog" /> class to use a specific connection string for | |
| /// connecting to the database. | |
| /// </summary> | |
| /// <param name="connectionString">The connection string to use.</param> | |
| public CustomSqlErrorLog(string connectionString) : base(connectionString) | |
| { | |
| } | |
| /// <summary> | |
| /// Logs an error to the database. | |
| /// Will also store the id of the saved error in the current http context items. | |
| /// </summary> | |
| /// <remarks> | |
| /// Use the stored procedure called by this implementation to set a | |
| /// policy on how long errors are kept in the log. The default | |
| /// implementation stores all errors for an indefinite time. | |
| /// </remarks> | |
| /// <param name="error">The <see cref="Error" /> to log.</param> | |
| /// <returns>Returns the id of the <see cref="Error" />.</returns> | |
| public override string Log(Error error) | |
| { | |
| var errorId = base.Log(error); | |
| HttpContext.Current.Items[HttpContextItemKey] = errorId; | |
| return errorId; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @using Project | |
| @model HandleErrorInfo | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta name="viewport" content="width=device-width" /> | |
| <title>Error</title> | |
| </head> | |
| <body> | |
| <hgroup> | |
| <h1>Error.</h1> | |
| <h2>An error occurred while processing your request.</h2> | |
| </hgroup> | |
| <p>Please provide you support contact with the following error code: <code>@HttpContext.Current.Items[CustomSqlErrorLog.HttpContextItemKey].ToString()</code></p> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment