1

I am trying to handle 404 error in MVC, all other error are being handle using angular so in dont have to worry about other exceptions.

I am handling the 404 error in the Global.asax page like this

 protected void Application_Error() { // if (Context.IsCustomErrorEnabled) ShowCustomErrorPage(Server.GetLastError()); } private void ShowCustomErrorPage(Exception exception) { var httpException = exception as HttpException ?? new HttpException(500, "Internal Server Error", exception); Response.Clear(); var routeData = new RouteData(); routeData.Values.Add("controller", "ErrorHandling"); routeData.Values.Add("fromAppErrorEvent", true); switch (httpException.GetHttpCode()) { case 404: routeData.Values.Add("action", "HttpError404"); break; } Server.ClearError(); IController controller = new ErrorHandlingController(); controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData)); } 

but when the 404 error occurs the the Execute method

controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));

renders the html of the page instead of the page itself, how to make changes so that i will be able to render the page itself not the html of the page.

1 Answer 1

1

write following code on your web config

<customErrors mode="On" > <error statusCode="404" redirect="~/Controller/CustomErrorPage" /> </customErrors> 
Sign up to request clarification or add additional context in comments.

1 Comment

i am handling all the remaining errors using my angular app, i just want to handle the 404 error, how can i do that, appreciate your help

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.