Dimitri
Dimitri

Reputation: 2858

catching exception thrown By CustomAuthorizeAttribute ASP.NET MVC 4

Suppose I have A CustomAuthorizeAttribute and I thew Exception in HandleUnauthorizedRequest. Is there any way to catch that exception and format the message and display it to the user. If not than how should a thing like this be implemented.

Upvotes: 0

Views: 62

Answers (1)

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93424

Do you want to do this globally? Or on a per controller basis?

If Globally, then you can create your own HandleErrorAttribute which will catch any unhandled exceptions. You can then test if the exception is HandleUnauthorizedRequest or not.

If you want to do this on a per controller basis, then you can override OnException and handle it there.

Upvotes: 1

Related Questions