letsgetsilly
letsgetsilly

Reputation: 1196

301 Redirect using Response Header fails to redirect properly

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.

Upvotes: 0

Views: 1458

Answers (2)

Bryan
Bryan

Reputation: 8788

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

Upvotes: 1

Mark
Mark

Reputation: 475

The code you posted worked fine for me.

You can try to use the RedirectPermanent method.

Upvotes: 1

Related Questions