Using Custom MvcHttpHandler v2.0 Breaking Change from 1.0 to 2.0?

I have a website where part is webforms (Umbraco CMS) and part is MVC. This is the HttpHandler for working with MVC functions:

public class Mvc : MvcHttpHandler { protected override void ProcessRequest(HttpContext httpContext) { httpContext.Trace.Write("Mvc.ashx", "Begin ProcessRequest"); string originalPath = httpContext.Request.Path; string newPath = httpContext.Request.QueryString["mvcRoute"]; if (string.IsNullOrEmpty(newPath)) newPath = "/"; httpContext.Trace.Write("Mvc.ashx", "newPath = "+newPath ); HttpContext.Current.RewritePath(newPath, false); base.ProcessRequest(HttpContext.Current); HttpContext.Current.RewritePath(originalPath, false); } } 

Details on how this is implemented here. This method works well on the MVC 1.0 website. However, when I upgrade this site to MVC 2.0, following the instructions in the Microsoft Update Documentation ; everything compiles except at runtime. I get this exception:

Server error in application "/".
Resource is not found.
Description: HTTP 404. The resource you are looking for (or dependencies) might have been deleted, changed its name, or temporarily unavailable. please review the following URL and make sure it is spelled correctly.

Requested URL: /mvc.ashx

Version Information: Microsoft.NET Framework Version: 2.0.50727.4927; ASP.NET Version: 2.0.50727.4927

This resource and its dependencies are found in MVC 1.0, but not in MVC 2.0, is there an additional dependency that I will need to add? Is there something I'm missing? Are there any changes to MVC 2.0?

0
source share
2 answers

A word of caution - the types MvcHandler and MvcHttpHandler are not subclassed by user code. These handlers will change with future versions of the framework, so any types whose subclasses are to be broken down. With that in mind.

In MVC 2, the type of MvcHttpHandler is IHttpAsyncHandler, not just IHttpHandler. This changes the semantics of how ASP.NET executes the handler. If you subclass MvcHttpHandler, you need to override the BeginProcessRequest and EndProcessRequest methods in addition to the ProcessRequest method.

A safer mechanism would be to wrap MvcHttpHandler rather than subclassing it. That is, make your own IHttpHandler, whose ProcessRequest () method simply delegates the new MvcHttpHandler.ProcessRequest (). Thus, changes in the operation of MvcHttpHandler should not cause damage to the cover handler.

+3
source

This is what I did and it works ...

 public class mvc : IHttpHandler, System.Web.SessionState.IRequiresSessionState { public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext httpContext) { string originalPath = httpContext.Request.Path; HttpContext.Current.RewritePath(httpContext.Request.ApplicationPath, false); IHttpHandler httpHandler = new MvcHttpHandler(); httpHandler.ProcessRequest(HttpContext.Current); HttpContext.Current.RewritePath(originalPath, false); } } 
+3
source

All Articles