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 7771569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:41:03+00:00 2026-06-01T16:41:03+00:00

This must be simple and already answered, but I’ve wasted many hours on it.

  • 0

This must be simple and already answered, but I’ve wasted many hours on it. I can’t figure how to get an error page on mistyped address. Also I’d prefer not to redirect, but to keep the URL. I’ve tried many combinations of CustomErrors, HttpErrors and Application_Error, but nothing works for non-existent controller – depending on HttpErrors I always get IIS 404.0 page or just an empty 404 response. Running on IIS 7.5, MVC 3.

  • 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-06-01T16:41:04+00:00Added an answer on June 1, 2026 at 4:41 pm

    I don’t remember where I got the solution. But here is the code to handle the error:
    First, you create a ErrorController:

    public class ErrorController : Controller
    {
        //
        // GET: /Error/
        public ActionResult Index()
        {
            return RedirectToAction("Index", "Home");
        }
    
        public ActionResult Generic()
        {
            Exception ex = null;
            try
            {
                ex = (Exception)HttpContext.Application[Request.UserHostAddress.ToString()];
            }
            catch { }
    
            return View();
        }
    
        public ActionResult Error404()
        {            
            return View();
        }
    }
    

    Second, open Global file and add the following code:

    protected void Application_Error(object sender, EventArgs e)
    {
         Exception ex = Server.GetLastError();
         Application[HttpContext.Current.Request.UserHostAddress.ToString()] = ex;
    }
    

    Third, change customerror in your webconfig:

    <customErrors mode="Off" defaultRedirect="/Error/Generic">
      <error statusCode="404" redirect="/Error/Error404"/>
    </customErrors>
    

    More: I created one more error layout. It makes things even more clear. 🙂

    Hope this helps you.

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

Sidebar

Related Questions

This must be simple, but I can't seem to figure it out. I am
This must be quite simple but I can't seem to figure this out. I've
This must be very simple. But I just can't seem to find the proper
This must be so simple, but I can't find it: How do you restore
this must be such a simple problem but can someone tell me why this
I must be missing something very simple, but can't find the answer to this.
Sorry if this seems pretty dumb but simple but I can't seem to figure
This must be very simple, but I couldn't find it on the documentation. In
There must be a simple solution to this problem but for the love of
Seems simple but I can't figure it out. I need to change the style

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.