views:

1764

answers:

1

I want to go beyond the default error handling given in ASP mvc. I have an errors controller, so I can hopefully give different error messages according to whats happened: i.e Invalid arguments, Permission denied, OMG DATABASE DEAD, etc.

But I cant seem to work out how to do this, this is what I have tried:

[HandleError(View="/Errors/InvalidArgument",ExceptionType=typeof(ArgumentException))]

It ends up giving a Runtime Error.

Also, on the same subject, is it possible to add more parameters that I could pass to the error controller, such as:

[HandleError(View="/Errors/InvalidArgument",ExceptionType=typeof(ArgumentException), Error="dumb arguments")]

Thanks

+2  A: 

Just specify the View name, not it's path...as for passing arguments, I don't think you can.

Kieron
I tried that, it didnt work...how would it know what controller to go to anyway?
qui
It won't go to a controller, it'll go to the view. If you want to go to a specific controller, you'll have to catch the exception and redirect yourself (I think). You can use the TempData to store the exception details. You may be able to write an ActionFilter to do the job...
Kieron
It doesn't "go to a controller." It just specifies a view name, like Kieron said. Look at the source code; it's trivial. The view name is resolved like any other view name, first in current controller, then in shared (in the default WebForms ViewEngine, anyway).
Craig Stuntz
What if it isn't in shared?
qui
Either make it shared or you can write a resolver to find it...
Kieron