3

I moved some of my old asp pages to new aspx website. In all of the old pages i used (for file example.asp):

Response.Status = "301 Moved Permanently"; 
Response.AddHeader("Location","http://www.example.com/example.aspx");

The problem is that when the page example.com/example.asp?param=value&param2=value2
is requested - the redirect ain't working...

Anyone...?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
beytz
  • 63
  • 4

3 Answers3

2

This solution will work from a classic ASP page. Basically an example of what smelch said.

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.test.com/default.aspx?" + Request.QueryString
Response.End
%>
dbasch
  • 1,698
  • 1
  • 15
  • 31
0

Add the query string parameters to the end of the location header, separated by a question mark. I believe it is in Request.Url.Query.

smelch
  • 2,483
  • 1
  • 18
  • 19
0

You could try something like this to ensure the query-string is carried across:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Status = "301 Moved Permanently";
    string sQueryString = this.Request.ServerVariables["QUERY_STRING"];
    Response.AddHeader("Location", String.Format("http://www.domain.com/example.aspx?{0}",   sQueryString));
}
bigtv
  • 2,611
  • 5
  • 29
  • 42