简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM