jumpstart0321
asked on
ASP.net 301 redirect code.
Ok, I have the following code to make sure that www.webspider.com is displayed all the time versuse webspider.com.
Dim domain_Name, theURL, QUERY_STRING, HTTP_PATH
domain_Name = LCase(Request.ServerVariab les("HTTP_ HOST")).To String
If domain_Name <> "www.webspider.com" Then
HTTP_PATH = Request.ServerVariables("P ATH_INFO")
If Left(HTTP_PATH, 8) = "Default.aspx" Then
HTTP_PATH = ""
End If
QUERY_STRING = Request.ServerVariables("Q UERY_STRIN G")
theURL = "http://www.webspider.com" & HTTP_PATH
If Len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
End If
Response.Clear()
Response.Status = "301 Moved Permanently"
Response.AddHeader("Locati on", theURL)
Response.Flush()
Response.End()
End If
The problem is, when I'm testing new code and there's the "localhost" header it tries to redirect to the website. Yes, I can comment it out but having to do this every time I modify my code is a pain. Anyone know how to properly add "localhost" to the options? I've tried several ways with no success.
Dim domain_Name, theURL, QUERY_STRING, HTTP_PATH
domain_Name = LCase(Request.ServerVariab
If domain_Name <> "www.webspider.com" Then
HTTP_PATH = Request.ServerVariables("P
If Left(HTTP_PATH, 8) = "Default.aspx" Then
HTTP_PATH = ""
End If
QUERY_STRING = Request.ServerVariables("Q
theURL = "http://www.webspider.com" & HTTP_PATH
If Len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
End If
Response.Clear()
Response.Status = "301 Moved Permanently"
Response.AddHeader("Locati
Response.Flush()
Response.End()
End If
The problem is, when I'm testing new code and there's the "localhost" header it tries to redirect to the website. Yes, I can comment it out but having to do this every time I modify my code is a pain. Anyone know how to properly add "localhost" to the options? I've tried several ways with no success.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here's what worked. I simply created a condition to test for localhost and only if it's not found test webspider. Sort of similar to the first answer:
Dim domain_Name, theURL, QUERY_STRING, HTTP_PATH
domain_Name = LCase(Request.ServerVariab les("HTTP_ HOST")).To String
If domain_Name <> "localhost" Then
else if domain_Name <> "www.webspider.com" Then
HTTP_PATH = Request.ServerVariables("P ATH_INFO")
If Left(HTTP_PATH, 8) = "Default.aspx" Then
HTTP_PATH = ""
End If
QUERY_STRING = Request.ServerVariables("Q UERY_STRIN G")
theURL = "http://www.webspider.com" & HTTP_PATH
If Len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
End If
Response.Clear()
Response.Status = "301 Moved Permanently"
Response.AddHeader("Locati on", theURL)
Response.Flush()
Response.End()
End If
end if
Dim domain_Name, theURL, QUERY_STRING, HTTP_PATH
domain_Name = LCase(Request.ServerVariab
If domain_Name <> "localhost" Then
else if domain_Name <> "www.webspider.com" Then
HTTP_PATH = Request.ServerVariables("P
If Left(HTTP_PATH, 8) = "Default.aspx" Then
HTTP_PATH = ""
End If
QUERY_STRING = Request.ServerVariables("Q
theURL = "http://www.webspider.com" & HTTP_PATH
If Len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
End If
Response.Clear()
Response.Status = "301 Moved Permanently"
Response.AddHeader("Locati
Response.Flush()
Response.End()
End If
end if
Like in debug write code for localhost and in Release mode write code for actual path
like
#if DEBUG
theURL = "http://localhost" & HTTP_PATH
#else
theURL = "http://www.webspider.com" & HTTP_PATH