I am developing a project in C# MVC 5.
When developing I prefer to switch off exception handling e.g. in Global.asax.cs:
#if !DEBUG
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
// save exception inf to DB
Server.ClearError();
Response.Redirect("/Home/Error");
}
#endif
in my web.config I have two options:
<system.web>
<!--<customErrors mode="Off"></customErrors> -->
<!-- or -->
<customErrors mode="On">
<error statusCode="404" redirect="~/Home/NotFound"/>
</customErrors>
</system.web>
The problem is that I have to edit it manually and it would be nice if it was changed automatically when the program is running in debug/release mode.
I there a way to in my program to change in the code? I want something like:
MyFunction()
{
#if DEBUG
SetCustomError("mode", "Off");
#else
// Keep web.config content
#endif
}
And where in the MVC structure can I do it?