Quick References
ADO
ASP
CSS2
HTML
JavaScript
Jet SQL
VBScript
WML
WMLScript
WSH
XHTML
XML DOM
XSLT
Features
Knowledge Base
Tutorials
Partners
ZVON.ORG
XML
Planet Source Code
VisualBuilder
Web Design
Your HTML Source
XML/XSLT Forums
ASPAlliance
Scripts
Programmers Heaven
Tek-Tips Forums
Developer Fusion
Code Project
A100233: Preventing HTTP 400 Bad Request Errors.
When requesting a page in Netscape whose URL contains spaces in a querystring, IIS will return an HTTP 400 'Bad request' error. Take the following example:
Response.Redirect "URLEncodeTest.asp?Name=The Guru"
If we compare the URL in the browser's address bar after attempting redirection, we will see a difference in how Netscape renders it compared to Internet Explorer:
Internet Explorer - http://bfserver1/DGTest/URLEncodeTest.asp?Name=The%20Guru
Netscape - http://bfserver1/DGTest/URLEncodeTest.asp?Name=The Guru
Notice how Internet Explorer has replaced the space in the querystring value with '%20' while the URL in Netscape still has the space, which will cause IIS to return an HTTP 400 'Bad request' error with the following message:
'Due to malformed syntax, the request could not be understood by the server. The client should not repeat the request without modifications.'
The obvious solution is to use
Server.URLEncode
which applies URL encoding rules to a string of ASCII characters. Applying URLEncoding to the entire URL, however, will still produce an error, but this time it will be an HTTP 404 'Page not found' error, and this applies to both browsers. So, in this example:
strURL = Server.URLEncode("URLEncodeTest.asp?Name=The Guru")
Response.Redirect(strURL)
we will see the following URL in the location bar of both browsers after attempting redirection:.
http://bfserver1/DGTest/URLEncodeTest%2Easp%3FName%3DThe+Guru
Therefore, the answer is just to URLEncode the querystring value that contains the spaces, as in the following error-free, cross-browser compatible example:
strValue = Server.URLEncode("The Guru")
Response.Redirect "URLEncodeTest.asp?Name=" & strValue
This produces the URL below in the address bar of both browsers:
http://bfserver1/DGTest/URLEncodeTest.asp?Name=The+Guru
The Guru
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information
knoxville photographer
knoxville wedding photographer