Registering custom error 500 handling (with e-mail send) on startup
Hey there,
I've created a method to send the StackTrace exception to me in an e-mail and want to ensure it's called upon when an error 500 gets fired. I have a new Global class implemented, but am unsure of how to get it called by default. Any thoughts?
This is all in Global.ascx.cs. NOTE that the ApplicationComposer class inheritance isn't rendering properly here, so FYI, ComponentComposer's T<> is ApplicationComponent and uses IUserComposer.
public class ApplicationComposer : ComponentComposer
{
public override void Compose(Composition composition)
{
composition.SetDefaultRenderMvcController(typeof(Controllers.MasterController));
if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Tls12) == false)
{
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
}
base.Compose(composition);
}
}
public class Global : UmbracoApplication
{
private Utilities _utilities = new Utilities();
protected override void OnApplicationError(object sender, EventArgs e)
{
Exception ex = HttpContext.Current.Server.GetLastError();
_utilities.SendErrorEmail(ex);
}
}
public class ApplicationComponent : IComponent
{
public void Initialize()
{
}
public void Terminate()
}
}
}
I've not done this in umbraco yet, but have setup custom error pages in MVC, it is not simple I'm afraid.
I will dig out some instructions for you, but you will need to add some stuff to the web.config and use a controller/method to send the email and render your custom 500 page.
You will also need to create some .hml and .aspx pages as fall back incase umbraco or your code causes an error otherwise you will probably get an err too many redirects from your error page.
Thanks, Huw. Yes -- it's hitting the custom error controller that I'm having trouble with... i.e. where and how to register that controller as the go-to upon 500 errors.
These are the instructions I followed. It works for a standard .Net mvc sites, I will give it a try out in Umbraco next week. I know for sure there a couple of umbraco config settings to change to use custom 404, so not sure if the same is tru for custom 500
I have this already setup in web.config, so maybe I wasn't clear. I'm unclear as to how to register a default action that handles errors. Outside of Umbraco, this is a piece of cake in Global.ascx.cs, but Umbraco 8 needs its own method that I haven't been able to find. That "override" method should call upon a public email sending method I've created.
Registering custom error 500 handling (with e-mail send) on startup
Hey there,
I've created a method to send the StackTrace exception to me in an e-mail and want to ensure it's called upon when an error 500 gets fired. I have a new Global class implemented, but am unsure of how to get it called by default. Any thoughts?
This is all in Global.ascx.cs. NOTE that the ApplicationComposer class inheritance isn't rendering properly here, so FYI, ComponentComposer's T<> is ApplicationComponent and uses IUserComposer.
Thanks for any help!
I've not done this in umbraco yet, but have setup custom error pages in MVC, it is not simple I'm afraid.
I will dig out some instructions for you, but you will need to add some stuff to the web.config and use a controller/method to send the email and render your custom 500 page.
You will also need to create some .hml and .aspx pages as fall back incase umbraco or your code causes an error otherwise you will probably get an err too many redirects from your error page.
Thanks, Huw. Yes -- it's hitting the custom error controller that I'm having trouble with... i.e. where and how to register that controller as the go-to upon 500 errors.
Apologies for delay, been a bit busy with work. I will dig out the code I have over the weekend and post it.
These are the instructions I followed. It works for a standard .Net mvc sites, I will give it a try out in Umbraco next week. I know for sure there a couple of umbraco config settings to change to use custom 404, so not sure if the same is tru for custom 500
Asp.Net MVC custom error handling
Huw,
Thanks for taking the time to find this.
I have this already setup in web.config, so maybe I wasn't clear. I'm unclear as to how to register a default action that handles errors. Outside of Umbraco, this is a piece of cake in Global.ascx.cs, but Umbraco 8 needs its own method that I haven't been able to find. That "override" method should call upon a public email sending method I've created.
Does that make sense?
Will keep searching. Thanks again.
sorry for long delay, I've been a bit busy with work.
I have Umbraco displaying a standard Umbraco page in response to a HttpUnhandledException
All I did for that was to create a page called error500 and point web config at that
you should then be able to call a controller action from that which sends an email
I throw an unhandled error in one of my controllers and it directed me to my custom error500 page
is working on a reply...