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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:02:19+00:00 2026-05-24T02:02:19+00:00

We have a section of code which detects old URL’s and performs a redirect

  • 0

We have a section of code which detects old URL’s and performs a redirect as follows:

Response.Clear();
Response.StatusCode = 301;
Response.Status = "301 Moved Permanently";
try
{
    Response.AddHeader("Location", MyLink.GetFullPath());
} catch
{
    Response.StatusCode = 302;
    Response.Status = "302 Moved Temporarily";
    Response.AddHeader("Location", "/");
}
Response.End();

What is essentially happening is that there is an attempt at a 301 permanent redirect and if this is not successful then a “302 Moved Temporarily” is thrown to the default home page.

PROBLEM: The problem I’m encountering is as follows. If a URL entered (lets say “/product/ABC123” for example). The URL 301 redirection fails and the 302 redirect in the catch is executed, however the original URL (“/product/ABC123”) is still executed in the background. When I run the website in the debugger, the 302 redirect works fine and the default home page comes up and then half a second later a supplementary page is executed and comes up with a server 500 error due to the fact that the original URL is no longer acceptable.

My question is as follows: How can I completely stop the original request and just let the 302 redirect do what it needs to do. I have tried “HttpContext.ApplicationInstance.CompleteRequest();” beneath the “Response.End()” but it did not stop the original request.

EDIT: The redirection code is being executed from the Index method of a Controller class.

  • 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-24T02:02:20+00:00Added an answer on May 24, 2026 at 2:02 am

    If you are in a controller action, exit the action method with returning a new HttpStatusCodeResult(302).

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

Sidebar

Related Questions

I have following Code Block Which I tried to optimize in the Optimized section
I have a section of code that can be summarised as follows; void MyFunc()
I have a section of code which returns events generated by a slider. I
I have critical section in my application which contains a lot of code: which
I have a section of code that is being used to determine if a
I have the following section of code in an app that I am writing:
I have some VERY simple code to return the title for a section header:
I have the following code which fetches a string from an array of strings
I have the code below which I am using to upload files to my
I have a section of code in a controller that replaces existing HTML with

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.