Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6176447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:06:16+00:00 2026-05-24T00:06:16+00:00

I’ve read many articles and several post (including here in stackoverflow) but do not

  • 0

I’ve read many articles and several post (including here in stackoverflow) but do not know what I’m doing wrong.

Here my code:

Global.asax.cs

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new HandleErrorAttribute());
}

ErrorControler.cs

public class ErrorController : Controller
{
    public ActionResult Error404()
    {
        return View();
    }

    public ActionResult Error500()
    {
        return View();
    }
}

Web.config

<customErrors mode="On" defaultRedirect="~/Error/Error500">
  <error statusCode="404" redirect="~/Error/Error404"/>
</customErrors>

MyController.cs

public ActionResult Index()
{
    using (var db = new DataContext())
    {
        int a = 2, b = 0;
        var r = a / b;
        return View(r);
    }
}

Error500.cshtml

@model System.Web.Mvc.HandleErrorInfo
@{
    ViewBag.Title = "Erro";
}

<h2>@ViewBag.Title</h2>
<div id="error-info">
    <p>Ocorreu um erro inexperado na página <a class="error-url" href="@Response["aspxerrorpath"]" title="Origem do erro">@Response["aspxerrorpath"]</a></p>
    <p>Se o erro persistir, por-favor, entre em contato com os administradores do site.</p>
    <div class="error-details">
        <p>@Model.Exception.Message</p>
    </div>
</div>

When I try to access the path /MyController the following message appears:

Server Error in ‘/’ Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.

Requested URL: /Error/Error500

I would like that happen when an error on any controller, if the http status code has not been informed in web.config, it redirects to the default view Error500

In this article, for example, it handles DbException errors, but would like to handle any type of error.

Errors of type 404 (page not found) works perfectly. The user is redirected to the page Error404.cshtml

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:06:17+00:00Added an answer on May 24, 2026 at 12:06 am

    If you want this to happen remove/comment the following line from your Global.asax:

    filters.Add(new HandleErrorAttribute());
    

    You basically have to choose whether you want ASP.NET to handle your errors (the <customErrors> section in your web.config) or ASp.NET MVC (the global HandleErrorAttribute action filter, which by the way requires you to turn on custom errors in web.config)

    Or checkout an alternative method for handling errors in ASP.NET MVC (with this approach you still have to remove the line I showed from your Global.asax).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.