Constructing my own HttpRequest object

2.9k Views Asked by At

Firstly let me state that We are NOT using IIS as our web server and do not intend to, so please no answers telling me to use IIs. The application I am working on's strength is that it does not require an IIS Server to be installed.

Secondly, I am not making a request (I'm not a client), I am the server and am accepting the requests via a 3rd party embedded lightweight web server.

To keep things .NET based and so I don't have to reference my 3rd party web server library for dynamically loaded modules, I would like to use the System.Web namespace that IIS uses, as it's there in .NET.

What I am having problems with is that I cannot fully create my own System.Web.HttpRequest object, nor can I extend my own (it's sealed) to overcome the problem.

How would I build a System.Web.HttpRequest object that I can translate information (such as headers, cookies, contentTypes, etc) from the 3rd party web server's handled requests to the .NET framework version?

1

There are 1 best solutions below

1
On

You can use the constructor internal HttpRequest(HttpWorkerRequest wr, HttpContext context). Pry it open using reflection. You then have to manufactore some other objects as well.

HttpWorkerRequest is made to be inherited from. No problem there. HttpContext has a constructor as well.

You might be forced to set other members using reflection as well. This scenario is barely supported.

ASP.NET MVC took the route of adding abstractions such as HttpRequestBase. Maybe you can migrate to use that.