Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Global Exception Handling for MVC controller
WhatsApp
Aravindhan Dhandapani
Jul 27
2015
957
0
0
using
System.Web.Mvc;
public
abstract
partial
class
BaseController : Controller
{
protected
override
void
OnException(ExceptionContext context)
{
base
.OnException(context);
string
controller = context.RouteData.Values[
"controller"
].ToString();
string
action = context.RouteData.Values[
"action"
].ToString();
if
(context.Exception !=
null
)
{
HandleErrorInfo errorModel =
new
HandleErrorInfo(context,controller,action);
if
(Request.IsAjaxRequest())
{
context.Result = View();
}
}
context.ExceptionHandled =
true
;
}
}
Global Exception Handling
MVC
controller
Up Next
Global Exception Handling for MVC controller