views:

85

answers:

5

When I check my page using those online host header analyzers, the page says 200 OK.

But when viewing in my browser, it redirects to another website (which is how I want it to be).

The code that I use is:

 context.Response.Status = "301 Moved Permanently";
 context.Response.AddHeader("Location", "http://www.example.com/article" + articleID);
 context.Response.End();

I put this code in a HttpModule.

it is working because when you try and hit the url, it does the redirect. It just doesn't seem to be returning the correct http header.

Is there something wrong?

A: 

Could you try using: HttpContext.ApplicationInstance.CompleteRequest()

Instead of Response.End()?

Kyle B.
A: 

Make sure the response buffer is completely clear before you add your headers:

context.Response.Clear();
context.Response.Status = "301 Moved Permanently";
context.Response.AddHeader("Location", "http://www.example.com/article" + articleID);
context.Response.End();
Oded
is there a way of checking how google sees it?
Blankman
Use a proxy like fiddler to see the headers. That's what google should see.
Oded
+1  A: 

try:

context.Response.StatusCode = 301;
context.Response.StatusDescription = "Moved Permanently";
context.Response.RedirectLocation = "http://www.example.com/article" + articleID;
context.Response.End();

I use the above in a custom module and it does return a proper 301 HTTP response.

KP
+1  A: 

Your code is exactly correct. I've used exactly what you've got for years:

context.Response.Status = "301 Moved Permanently";
context.Response.AddHeader("Location",URL);
context.Response.End();
TAG
A: 

When I use the HTTP logging in Web Development Helper, I see the 301 and the 200. So, yes, your code is correct.

DaveB
I was thought it should only be a 301?
Blankman