0

I have an MVC 4 app. I added a simple controller Get method that I am trying to call. I always get 404 error when I try to load the page.

HTML page that calls the method - demo.html page:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title></title></head>
<body>
    <video width="480" height="320" controls="controls" autoplay="autoplay">
        <source src="/vdo/?id=small.mp4" type="video/mp4" />
    </video>
</body>
</html>

Controller:

public class VdoController : ApiController
{

    [AllowAnonymous]
    public HttpResponseMessage Get(string id)
    {
        if (id == null)
            return new HttpResponseMessage(HttpStatusCode.BadRequest);
        .....

        HttpResponseMessage resp = Request.CreateResponse(HttpStatusCode.PartialContent);
        .....

        return resp;
    }         
}

Route Registration:

public override void RegisterArea(AreaRegistrationContext context)
{
      context.MapRoute(
                "Vdo",
                "vdo/{id}",
                new { controller = "Vdo" },
                new string[] { "<Namespace>.Controllers" }
            );    
}

What am I missing?

Here is what I see in browser: enter image description here

Here is the actual error I just got in debug mode:

The controller for path '/vdo/small.mp4' was not found or does not implement IController.

kheya
  • 7,546
  • 20
  • 77
  • 109

2 Answers2

0

when we use routing we don't need to use querystring to pass data in the url. i think your problem in your url, you written your route rule like- vdo/{id} but you are requesting for the controller function using querystring, you should change your url to-/vdo/small.mp4 from /vdo/?id=small.mp4 i think this will solve your problem.

Khairul Islam
  • 1,207
  • 1
  • 9
  • 20
0

I believe you need to map a default action to Get

  public override void RegisterArea(AreaRegistrationContext context)
    {
          context.MapRoute(
                    "Vdo",
                    "vdo/{id}",
                    new { controller = "Vdo", action = "Get" },
                    new string[] { "<Namespace>.Controllers" }
                );    
    }

Then you can use /vdo/small.mp4 to access it.

johnnycreaks
  • 101
  • 4
  • No difference. The actual error is still - "The controller for path '/vdo/small.mp4' was not found or does not implement IController." – kheya Dec 09 '15 at 18:22
  • Found this: http://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis , it seems your issue is the Handler not knowing what to do with the period in the id parameter. – johnnycreaks Dec 09 '15 at 18:25
  • No. If I take out the the dot, it still has same issue. – kheya Dec 09 '15 at 18:51
  • Can you try changing the Base Class to Controller instead of ApiContoller? – johnnycreaks Dec 09 '15 at 18:58
  • That gives other issues. Some part of the code will not compile. – kheya Dec 09 '15 at 19:00
  • Maybe implement what [this guy](http://www.strathweb.com/2013/01/asynchronously-streaming-video-with-asp-net-web-api/) did and see if it solves your problem. Also, ignore what I suggested in my answer about defining the default action as it is unnecessary. – johnnycreaks Dec 09 '15 at 19:06