I always faked / ridiculed / drowned out the HttpContext somehow in ASP.NET (much easier in ASP.NET MVC / MonoRail).
But I see that HttpContext itself can be built easily, literally with a couple of lines of code.
var tw = new StringWriter(); var workerReq = new SimpleWorkerRequest("/webapp", @"c:\here\there\wwwroot", "page.aspx", tw); var context = new HtpContext(workerReq);
If we include this code in something like this, it should work fine, and perhaps we can even make ASPX using this:
using(Simulate.HttpContext()) { HttpContext.Current.BlaBla; }
So the questions are:
- Reasons why this should NOT be done.
- Reasons why this MUST be done.
- Why is it not widely used (in fact, I do not remember any reports about this).
I remember one post in which Phill Haack built an HttpContext using Reflection hacks.
But it doesn't seem to be necessary.
Cheers
Dmitry.
Dmytrii nagirniak
source share