0

I am trying to handle 404 page not found exception in mvc and i just want to know the right approach to handle page not found. this is how i handle the 404 page not found exception

protected void Application_Error()
        {
            ShowCustomErrorPage(Server.GetLastError());
        }
        private void ShowCustomErrorPage(Exception exception)
        {
            var httpException = exception as HttpException;

            if (httpException.GetHttpCode() == 404)
            {
                Response.Redirect("PagenotFound");
            }
        }

is this the right approach !!!

Lijin Durairaj
  • 3,341
  • 11
  • 31
  • 50
  • Does it do what you want? – CodeCaster Sep 26 '17 at 09:00
  • actually yes, if the page not found exception is found, applicaiton_Error method gets called and i redirect it to the pageNotFound controller, is there any better way? i dont know the answer thats the reason i asked question in this forum – Lijin Durairaj Sep 26 '17 at 09:04
  • actually i tried this, https://stackoverflow.com/questions/46420981/how-to-call-a-page-using-icontroller-execute-method-in-mvc but i was not successful to call the page and there was no one to help me with the answer, thats the reason i changes my approach a little – Lijin Durairaj Sep 26 '17 at 09:05
  • Read the duplicate to your previous question. "The best way" or "the right approach" is not answerable. – CodeCaster Sep 26 '17 at 09:07
  • the duplicate for my previous question is also been asked by me and there was no answer, so i thought to ask another by changing the heading but was marked as duplicate instead – Lijin Durairaj Sep 26 '17 at 09:11
  • Yeah so perhaps stop asking new questions, take a step back and read the info provided. – CodeCaster Sep 26 '17 at 09:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/155306/discussion-between-lijin-durairaj-and-codecaster). – Lijin Durairaj Sep 26 '17 at 09:18
  • https://stackoverflow.com/questions/42268872/automatically-throw-404-exception-from-action-method-if-entity-object-is-null/42269170#42269170 – Animus Miles-Militis Sep 26 '17 at 09:29
  • @AnimusMiles-Militis this is the eaxact approach which i have used above right – Lijin Durairaj Sep 26 '17 at 09:35

0 Answers0