Convert ASHX ProcessRequest to MVC controller

675 Views Asked by At

I have an ashx file with the following method defined:

public void ProcessRequest(HttpContext context) ...

I want to move the code inside of it into an MVC controller. It's all code that can be easily run as-is in an MVC controller, but I'm not sure if I need to write it in a specific way to be able to get called the same way. I've tried the following:

[HttpPost] //in the TestController
public void Index()
{
    var context = HttpContext;
....

But it doesn't hit my breakpoint on the first line. Is there another way I need to set it up in order to replicate being called as ProcessRequest is called in an ASHX file?

EDIT: here's my route config:

    routes.MapRoute(
        name: "Test",
        url: "test/{action}",
        defaults: new { controller = "Test", action = "Index" }
    );
1

There are 1 best solutions below

0
On

It turns out that for my purposes, my action method had to be a GET, not a POST. Changing that fixed my problem.