HttpContext and Component Writing for WebForms and MVC

I am writing a component that I would like to use in MVC and WebForms web applications, but I am not sure how to handle the differences between HttpContext handling.

My component includes a custom IHttpHandler (for WebForms) or a custom ActionResult (for MVC).

So, I have a few questions:

  • Is there a way to use IHttpHandler with MVC without breaking the model?
  • Is it legal to use HttpContext.Current when trying to write code that will work for both? It seems a bit brute force to me (I'm not sure why), but the alternative would be to write and implement a rather verbose interface to handle the abstraction between HttpContext and ControllerContext.
  • Do I really disagree about this?
+1


source to share


1 answer


  • Yes, you can just use routes.IgnoreRoute("MyHandler.ashx")

    . It will fallback to the original ASP.NET processing without breaking the model.
  • No, I think that's great to use HttpContext.Current

    . I think that when you write your own handler, MVC is not very suitable. You are writing your code for ASP.NET , not ASP.NET MVC or ASP.NET Web Forms. Easy to get it to work on both models (OOTB works with web forms, with IgnoreRoute in MVC). You can make things harder than they need to be! Remember that the only purpose of design patterns (like MVC) is simplicity. Don't make things hard!
  • goto 2;

    Just write a simple handler!


+2


source







All Articles