OK any of you working with a CMS system based on ASP.net which utilises the Response.Redirect method to handle links will undoubtedly have come across this issue - those of you using ASP.net in general and considering using Response.Redirect should also read on...
Response.Redirect makes a round trip to the server and returns a
302 redirect in the headers. Now if you're in anyway concered about SEO you'll know that the majority of search engine bots won't follow 302 redirects (temporary redirects).
I actually came across this after monitoring Google on a DotNetNuke project which utitlises the LinkClick method (which pretty much handles all links in the TEXT/HTML module). So I know that any links to LinkClick.aspx?xxxx&yyyyy will return 302 redirects before going onto my real "seo-freindly" url... Which of course is a BIG problem.
Well after badgering around for what seems like weeks (but is probaly only a few minutes) I began to think about the global.asax file and how it handles requests.
I know there is the Application_PreSendRequestHeaders (which is processed just before we bat the response headers back to the client) so this seems like an appropriate place to check and rewrite the headers and this is actually quite a simple piece of code...
Sub Application_PreSendRequestHeaders(ByVal sender As Object, ByVal e As EventArgs) If Response.StatusCode = 302 Then Response.StatusCode = 301 End If End SubObviously you'll want to be specific in your catchment but you get the idea. I tested this with
LiveHTTPHeaders and it seems to have the desired affect - a 301 redirect. I'll let you know if Google likes it after Mr. Google-bot has come back to see my client's site. IN the meantime if your desired affect is to redirect to another file on your server I'd suggest you use the Server.transfer() method which doesn't make the round trip to the server.
Also check out
Matt Cutts blog article about this very issue
Labels: 301, 302, asp.net, dnn, dotnetnuke, optimisation, response.redirect, search engine, seo