tags:

views:

59

answers:

5

I'm writing a very small application for my organization. As nobody seems to know what he wants, I've decide that I'll deploy a demo on our local server so people can get ideas on how to conceive the big thing.

Now here's the problem: While developing on my laptop, when the application crashes, I get a yellow screen giving feedback on the problem (to me). But, if I decide to put the application online, I don't want those kind of yellow screen to be seen by others who are not developers (I know they might be a few because the demo is just a starting point).

Is there anyway I can put a mechanism in place so that when there's an fatal error, the user can get a nice screen telling with an e-mail link telling him to send me an e-mail?

Thanks for helping

+1  A: 

Similar to classic ASP.NET by using customErrors

veggerby
+2  A: 

Use the customErrors section of then root web.config to specify how your application handles errors.
In your case I would think that you would want to set this to RemoteOnly so that you can still see the errors on your local machine and set 500 errors to go to your contact form:

<configuration>
  <system.web>
    <customErrors defaultRedirect="Error.htm" mode="RemoteOnly">
      <error statusCode="500" redirect="ContactAdmin.htm"/>
    </customErrors>
  </system.web>
</configuration>
Andy Rose
+3  A: 

I'd recommend wiring ELMAH in your project, and adding the custom errors tag the other answers pointed to. This way you have a user-readable error page and full error tracing at your fingertips. You can also configure elmah to automatically send you an email with the details. The user doesn't even need to know it happened...

Priceless!

samy
+1 for ELMAH...
veggerby
A: 

Have a look at this I'm sure it'll solve all your problems. http://blogs.microsoft.co.il/blogs/shay/archive/2009/03/06/real-world-error-hadnling-in-asp-net-mvc-rc2.aspx

Nick Masao
+1  A: 

I would say the quick fix is to use try catch blocks. When you catch an error, send the user to a custom error controller and action. On this action you could have a form for them to email you... and in hidden fields you could have the exception, because you passed it to the action.

    try
    {
        int myvar = 0/4;
    }
    catch(Exception exceptionObject)
    {
        return RedirectToAction("HandledExceptionAction", "ErrorController", exceptionObject);
    }
CrazyDart