Why does HttpWorkerRequest fail during HttpRuntime.ProcessRequest after a .NET 2.0 to .NET 4.0 upgrade? -


i upgrading our application, has internal webserver, .net 2.0 .net 4.0.

i handling request object httplistenerworkerrequest, extends httpworkerrequest class, , creates request getrawurl() returns url in format of http://localhost:82/default.aspx.

in .net 2.0, sending httpruntime.processrequest(httplistenerworkerrequest) works without issue, in .net 4.0, web page nothing text "bad request" on it.

cracking open httpruntime, can see bad requests thrown processrequestinternal(httpworkerrequest wr), private method tries build httpcontext.

i tried myself:

try {     //what's going on?     hcontext = new httpcontext(workerrequest); } catch(exception e) {     //debugging break point here } 

pre-update (.net 2.0), builds fine, post-update (.net 4.0), system.argumentexception stating

the relative virtual path 'http:/localhost:82/default.aspx' not allowed here, thrown @

at system.web.virtualpath.create(string virtualpath, virtualpathoptions options)    @ system.web.httprequest.get_clientfilepath()    @ system.web.security.cookielesshelperclass.removecookielessvaluesfrompath()    @ system.web.httpcontext.init(httprequest request, httpresponse response)    @ system.web.httpcontext..ctor(httpworkerrequest wr)    @ talcasoft.web.hosting.httpworkerthread.run(object request) in          c:\[ourlibrary].web\hosting\httpworkerthread.cs:line 51 

what has changed in .net cause this, , can around it?

edit have noticed disallowed http: followed single slash, not double, although getrawurl() in request returns double.

i'm not 100% 'exact answer' looks pretty close me - , there more write...

there seems breaking change of sort inside virtualpath class - , it's substantiated how checking illegal characters. (btw. can google 'virtualpath source' seems .net 4 version of it).

inside virtualpath.create check invoked 'illegal virtual path characters'.

it first goes registry ("hkey_local_machine\software\microsoft\asp.net", "verificationcompatibility") - see if compatibility mode 'illegal chars' should used.

based on - i'm guessing (i don't have way of checking right now) - if set above registry value (int) 1 - you should methods working the old way , w/o additional effort. note: iis (or host process) restart may required suggested in 1 of links

and based on registry flag used either of these two...

':', '?', '*', '\0' // .net 4.0 - default '\0' // 'compatibility' mode   

that seems describe story quite path 'port' designation illegal per new default.


final edit / explanation:

(update based on comments , solution solved it)
understanding of what's going on inside:

1) solution prior .net 4.0 verificationcompatibility key (see above).

2) .net 4.0 internal handling , fixing of url paths made more robust. , works fine in cases. in short, all paths fixed , normalized before entering virtualpath.create - , http://... becomes expected absolute path /default.aspx.

however when supply httpworkerrequest (instead of request/response etc.) - raw url taken directly worker - and responsibility supplying correct , normalized paths down worker request. (this still bit iffy, , looks bug or bad handling internally).

to reproduce issue:

internal class myrequest : simpleworkerrequest {     public myrequest() : base("", "", string.empty, string.empty, null) { }     public override string getrawurl() { return "http://localhost:82/default.aspx"; } } // ... var wr = new myrequest(); var context1 = new httpcontext(wr); 

gives error the relative virtual path 'http:/localhost:82/default.aspx' not allowed here.

the fix:

public override string getrawurl()  { return new uri(url, urikind.relativeorabsolute).absolutepath; } 


, of research on subject based on verificationcompatibility keyword in registry seems key it.

ampersand in url filename = bad request

configure iis accept url special characters...

for 32 vs 64 difference in registry

and here similar thing microsoft - seems 'hotfix' '2.0', i.e. doesn't apply - attaching official in line.

fix: "http 400 - bad request" error message in .net framework 1.1
fix: error message when try visit asp.net 2.0-based web page: "httpexception (0x80004005): '/handlertest/webform1.aspx/a:b' not valid virtual path"
asp.net 2.0 x64 – may http 400 bad request or error mentioned in kb 932552 or 826437

hkey_local_machine\software\microsoft\asp.net

dword value name: verificationcompatibility  value data: 1


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -