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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:29:41+00:00 2026-06-08T12:29:41+00:00

I’ve got an ASP.NET app that sometimes redirects to a 404 page if requested

  • 0

I’ve got an ASP.NET app that sometimes redirects to a 404 page if requested content isn’t found. This is done something like this:

var data = MyDatabase.RetrieveData(dataID);
if (data == null)
   Response.Redirect("~/My404Page.aspx");

This works great for users. But it’s resulting in 302 Found (a redirect), not 404 Not Found, which is not ideal for search crawlers. I’d like to return a 404 status code and still display helpful content to the user.

The famous internet’s most awkard 404 page does this; if you enter a bad URL in that domain and watch the result with something like Fiddler, you actually get a 404 code back.

I’ve tried this:

Response.StatusCode = 404;

This sets the 404 code properly, but continues rendering the page. I’ve also tried this:

throw new HttpException(404, "Not Found");

But this does the same thing it would with any other uncaught exception (redirects via 302 to a server error page).

I’ve figured out a way to solve this in my app via some custom logic that involves setting the status code myself and writing a javascript redirect to the response. But what I’d like to have is a way to express in code-behind that this request should stop processing and redirect to the 404 error page (which I believe can be specified either in IIS or web.config). Is this possible?

  • 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-08T12:29:43+00:00Added an answer on June 8, 2026 at 12:29 pm

    You need to do a Server.Transfer rather than a Repsonse.Redirect if you don’t want the 302 redirect. Response.Redirect() sends a response back to the browser that tells it to load up your ~/My404Page.aspx. Server.Transfer() transfers control over to your ~/My404Page.aspx without going back to the browser, which means that your browser won’t get the 302 redirect message.

    You also need to make sure that you set the Response.StatusCode property to 404 on your 404 page.

    Alternatively, if you throw the HttpException, you can redirect to your custom 404 page without doing a 302 in the server by setting the redirectMode property to ResponseRewrite. This will only work in newer versions of ASP.NET.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.