tolsen64
tolsen64

Reputation: 999

ASP.NET site moved to new server. How do I redirect all page requests (including querystrings) to the same page on the new server?

My company has moved an internal web site to a different server. I have been asked to do the following when someone uses a link to the old site location:

Display a page that tells the user that the site has moved, display the new url, and ask the user to update their bookmarks, then after 15 seconds, redirect them to the new page location, including the querystring.

I've found example of using rewrites and redirects but it looks like they cover the entire server. I only want to redirect all pages for a single site on the server.

So i'm looking for how to redirect any request to a single site on an asp.net server to a "Please change your bookmark" page that will then forward them on to the same location on a different server. Appreciate all suggestions.

Edit: Clarification. For a single asp.net application within an asp.net site.

Upvotes: 0

Views: 309

Answers (1)

tolsen64
tolsen64

Reputation: 999

Figured it out so I'll post it here for others to find. In ASP.NET, I used a file called "app_offline.htm" and placed it in the root directory of the web application on the old server. Now when people hit any page in that app, they see the app_offline page. The code looks like this:

<html>
    <head>
        <title>This page has moved</title>  
    </head>
    <body>
        <h2 style="text-align:center">This page has been moved to:<br /><br />
            <a href="test" id="aNewLoc"><span id="spanNewLoc"></span></a><br /><br />
            Please update any bookmarks you may have.<br /><br />
            You may click the link to go there now, or wait <span id="spanTimeout">15</span> seconds to be redirected automatically.
        </h2>
    </body>

    <script type="text/javascript">
        var timeout = 15;
        document.getElementById("aNewLoc").href = newLoc();
        document.getElementById("spanNewLoc").innerText = newLoc();
        setTimeout(countDown, 1000);

        function newLoc() {
            return 'http://newurl.com' + location.pathname + location.search;
        }

        function countDown() {
            timeout = timeout - 1;
            document.getElementById("spanTimeout").innerText = timeout;
            if (timeout == 0) {
                window.location.href = newLoc();
            }
            else {
                setTimeout(countDown, 1000);
            }
        }

    </script>
</html>

Upvotes: 0

Related Questions