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

  • Home
  • SEARCH
  • 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 9002239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:32:36+00:00 2026-06-16T00:32:36+00:00

I am running an asp.net web application and, for search engine optimisation, would like

  • 0

I am running an asp.net web application and, for search engine optimisation, would like any domain name that I have bought to 301 redirect to my preferred domain name.

For testing purposes I added a Global.asax page to my localhost project and added the following code:

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e) 
{ 
  string currentUrl = HttpContext.Current.Request.Url.ToString();
  if(!currentUrl.StartsWith("http://www.mydomain.org")) 
  { 
    string strStart = currentUrl.Substring(0, currentUrl.indexOf(@"/Pages"));
    Response.Status = "301 Moved Permanently"; 
    Response.AddHeader("Location", currentUrl.Replace(strStart, "http://www.mydomain.org")); 
    Response.End(); 
  } 
}

I replaced the “http://www.mydomain.org” with one of my current domain names. It all ran as I wanted it to. However, now when I remove that code from the .asax file, or even remove the asax file completely, that snippet of code still runs. So effectively running my localhost project opens my online website and I cannot stop this behaviour.

I have done the following:

  • Deleted EVERYTHING in the “Temporary ASP.NET Files” folder
  • Deleted the .dlls in my /bin folder and the entire /obj folder
  • Cleaned and rebuilt my solution.
  • Created an entirely new solution, then added files to it. This works at first but with the addition of the Global.asax file the same behaviour occurs.

Although this is the behaviour I eventually want, I would like to run, debug and edit it after my first implementation of it. I have seen the same problem before but it was seemingly fixed by one of the above methods. Please help!

  • 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-16T00:32:37+00:00Added an answer on June 16, 2026 at 12:32 am

    Your problem has nothing to do with your code. It is caching of the 301 you are struggling with.

    Caching of 301 can happen in many places along the way your request is going through, starting form your browser and the behavior can become unpredictable because of this

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

Sidebar

Related Questions

We have a asp.net 2.0 web application that is running on IIS7. It is
I am running an ASP.NET web application that connects to the WSS 3.0 search
We have an ASP.NET web application running in IIS that uses the SoapHttpClientProtocol class
We have an ASP.Net Web Application that is running in an IIS Web-Garden--which is
We currently have an ASP.NET Web Application running on a single server. That server
I have an ASP.NET web application I'm running with VS2010 that has session timeout
We have an ASP.net web application and would like to host on Azure to
I have a ASP .Net web-application running on IIS 7/Win2K8 Standard. What I would
We have a ASP.Net web application running in Visual Studio 2010 that is targeting
I have a website that a converted into a web application running ASP.NET webforms.

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.