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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:11:10+00:00 2026-05-22T23:11:10+00:00

I have tried the following 2 things to have a page return a 404

  • 0

I have tried the following 2 things to have a page return a 404 error:

public ActionResult Index()
{
    return new HttpStatusCodeResult(404);
}

public ActionResult NotFound()
{
    return HttpNotFound();
}

but both of them just render a blank page. How can I manually return a 404 error from within ASP.NET 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-05-22T23:11:11+00:00Added an answer on May 22, 2026 at 11:11 pm

    If you inspect the response using fiddler, I believe you’ll find that the blank page is in fact returning a 404 status code. The problem is no view is being rendered and thus the blank page.

    You could get an actual view to be displayed instead by adding a customErrors element to your web.config that will redirect the user to a specific url when a certain status code occurs which you can then handle as you would with any url. Here’s a walk-through below:

    First throw the HttpException where applicable. When instantiating the exception, be sure to use one of the overloads which takes a http status code as a parameter like below.

    throw new HttpException(404, "NotFound");
    

    Then add an custom error handler in your web.config file so that you could determine what view should be rendered when the above exception occurs. Here’s an example below:

    <configuration>
        <system.web>
            <customErrors mode="On">
              <error statusCode="404" redirect="~/404"/>
            </customErrors>
        </system.web>
    </configuration>
    

    Now add a route entry in your Global.asax that’ll handle the url “404” which will pass the request to a controller’s action that’ll display the View for your 404 page.

    Global.asax

    routes.MapRoute(
        "404", 
        "404", 
        new { controller = "Commons", action = "HttpStatus404" }
    );
    

    CommonsController

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

    All that’s left is to add a view for the above action.

    One caveat with the above method: according to the book “Pro ASP.NET 4 in C# 2010” (Apress) the use of customErrors is outdated if you’re using IIS 7. Instead you should use the httpErrors section. Here’s a quote from the book:

    But although this setting still works with Visual Studio’s built-in test web
    server, it’s effectively been replaced by the <httpErrors> section in IIS 7.x.

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

Sidebar

Related Questions

In the controller: public ActionResult Index() { ViewData[page] = 0; return View(data); } public
I have the following code: public static function check($ip,$op,$page) { $con = new PDO(DBN,DB_USER,DB_PASS);
I have tried following queries to get my facebook fan page insights data SELECT
I am pretty new to jqm i have tried about 20 different things and
I have tried the following <input type=file name=upload multiple=multiple value=MyText> However the text on
I have tried the following MySQL update but it only sets the first field
I have tried the following program for writing the contents into Spreadsheet. I downloaded
I have tried the following: <%= image_tag '...path_to_img', :filter => alpha(opacity=50) %> But it
I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,
I have tried the following code: $('a.buildMenu').click(function (event) { // Prevent normal behaviour event.preventDefault();

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.