I am upgrading our application, which has an internal webserver, from .NET 2.0 to .NET 4.0.
I am handling a request with an object HttpListenerWorkerRequest
, that extends the HttpWorkerRequest
class, and creates a request which GetRawUrl()
returns a Url in the format of http://localhost:82/Default.aspx
.
In .NET 2.0, sending this to HttpRuntime.ProcessRequest(httpListenerWorkerRequest)
works without issue, however in .NET 4.0, I get a web page with the nothing but the text "Bad Request" on it.
Cracking open HttpRuntime
, I can see that Bad Requests are thrown from ProcessRequestInternal(HttpWorkerRequest wr)
, a private method that tries to build an HttpContext.
I tried this myself:
try
{
//what's going on?
hcontext = new HttpContext(workerRequest);
}
catch(Exception e)
{
//Debugging break point here
}
Pre-update (.NET 2.0), it builds fine, post-update (.NET 4.0), I get a System.ArgumentException stating that
The relative virtual path 'http:/localhost:82/Default.aspx' is not allowed here
, thrown at
at System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options)
at System.Web.HttpRequest.get_ClientFilePath()
at System.Web.Security.CookielessHelperClass.RemoveCookielessValuesFromPath()
at System.Web.HttpContext.Init(HttpRequest request, HttpResponse response)
at System.Web.HttpContext..ctor(HttpWorkerRequest wr)
at Talcasoft.Web.Hosting.HttpWorkerThread.Run(Object request) in
C:\[OurLibrary].Web\Hosting\HttpWorkerThread.cs:line 51
What has changed in .NET to cause this, and what can I do to get around it?
EDIT I have just noticed that the disallowed http: is followed by a single slash, not a double, although the GetRawUrl() in the request certainly returns a double.