Need to hail your server administrators when something goes wrong with your servers? We've got you covered - today we'll cover adding notifications on server exceptions to your C# ASP.NET MVC application. We'll cover all the key plumbing to make it happen!
Why wait? Click the button below to move to the next step of the tutorial.
Here we create a list of administrators who should be notified if a server error occurs. The only essential piece of data we need is a
PhoneNumber for each administrator.
With this list in hand, let's configure the Twilio REST client and see how we use it to send a notification on application exceptions.
Now that we have our Twilio Client setup, let's see how to handle exceptions.
In an ASP.NET MVC application, we can handle errors at the application level. Note that any other exceptions caught in the code (using your own try/catch blocks) are not being captured and processed here.
Any uncaught exception will be handled here. Let's see how we can use this exception to hail our administrator list.
Here we create an alert message to send out via text message. You might also decide to include a picture with your alert message... maybe a screenshot of the application when the crash happened? A meme to calm everyone down?
The error handling is setup to capture application wide errors and forward them to all the lucky administrators.
Let’s take a closer look at how the Notifier forwards these errors to the administrators.
We've seen how to load a list of administrators from a file. Now let's see how to send a message to each of them.
That's it! We've just implemented an automated server notification system that can send out C# ASP.NET MVC server alerts if anything goes wrong.
Let's see some other fine features you can add to your application, next.
Twilio and C# are great together! Here are two more ideas for useful features:
Increase the security of your login system by verifying a user's mobile phone in addition to their password.
Send your customers a text message when they have an upcoming appointment, this tutorial shows you how to do it from a background job.
Thanks for checking out this tutorial! Tweet us @twilio to let us know what you've built... and what you're building.