views:

17

answers:

1

I have found this. http://geekswithblogs.net/shahed/archive/2007/10/23/116278.aspx

Can some help me organise this into an aspx/aspx.cs file as I'm not overly familiar with all the code here.

Hi,

I have built a new website using asp.net. The previous version was built using asp. Here is the problem. My client wants 301 permanent redirects on pages with query strings.

How do I go about redirecting from a page that doesn't exist on my server any more eg.

From

www.mydomain.com/dolls/detail.asp?id=15

to

www.mydomain.com/search_results.aspx?section=Dolls&title=Hat

I have read a few articles but they don't explain how to remedy this particular problem.

Many thanks, C

A: 

1) Apache: Redirect 301 /detail.asp?id=15 http://www.mydomain.com/search_results.aspx?section=Dolls&title=Hat

2) IIS: there is a redirection page.

3) Edited: full code:

using System.Web;
public class PermaRedirectHandler : IHttpHandler
{
    public PermaRedirectHandler(){}

    public void ProcessRequest(HttpContext context)
    {
        Response.Status = "301 Moved Permanently";
        Response.RedirectLocation = RedirectionClass.GetRedirectUrl(context);
    }

    public bool IsReusable { get { return false; } }
}

In web config you would map all the paths ending .asp to the handler:

<system.webServer>
  <handlers>
    <add verb="*" path="*.asp" name="redir" type="PermaRedirectHandler" modules="IsapiModule"/>
  ...
  </handlers>
</system.webServer>

You will need a mapper for old=>new urls RedirectionClass.GetRedirectUrl. You could use a Dictionary<string, string> or whatever.

Jaroslav Jandek
This is not what he ask for. And how they going to run asp pages from aspx compiler ?
Aristos
Actually. Since he cannot suggest the paths, he could do it manually in server configuration.Also added code that will handle the redirection.
Jaroslav Jandek