Question

I'm attempting to implement a 301 redirect for purposes of url rewriting/SEO optimization. I'm performing these redirects within a module of my VB.NET website.

When I specify a new location in the header it always appends the new location onto the existing url instead of completely replacing it or using a relative path. So instead of a nice URL I get a combination of both:

http://site.com/productList.aspx?id=123&fid=123&mid=123http://site.com/store/books/

Here is the code that I'm using for the redirect:

httpContext.Response.Status = "301 Moved Permanently"
httpContext.Response.AddHeader("Location", "http://site.com/store/books")
httpContext.Response.End()

I've attempted to use relative ~/ paths with no success. I'm guessing that I'm doing wrong that is very simple. Please help! Thanks in advance.

Était-ce utile?

La solution

Are you trying to do this after ASP.NET has already started filling the response buffer? Try calling Response.Clear() first.

Autres conseils

The code you posted worked fine for me.

You can try to use the RedirectPermanent method.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top