views:

321

answers:

1

I am trying to add the path /_vti_bin/Lists.asmx to my ASP.NET MVC 2 web application.

I am registering the route as follows:

routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");
routes.Add(new Route("_vti_bin/Lists.asmx", new ListsHandler()));

where ListHandler is defined as:

public sealed class ListsHandler : IRouteHandler
{
    #region IRouteHandler Members

    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        throw new NotImplementedException();
    }

    #endregion
}

But when I start the MVC application and try to navigate to http://localhost:8888/_vti_bin/Lists.asmx, I get an HTTP 404 error, rather than an exception raised.

Is this even possible in MVC? Do I need to add an Lists.asmx ASPX web service file to my project in a particular place (I cannot create the _vti_bin folder in the Visual Studio project)?

Update: Darin's response enabled http://localhost:8888/_vti_bin/Lists.asmx to work now (the only difference is the order of the route definitions). But now, requesting the 'About' page of the default MVC 2 project site results in a request to http://localhost:8888/_vti_bin/Lists.asmx?action=About&controller=Home, not to the home controller!

Apparently the order in which the routes are defined matters.

A: 

This should work. Here are the steps I did:

  1. Start VS2010
  2. Create a new ASP.NET MVC 2 project using the template
  3. Modify Global.asax to look like this:

    public sealed class ListsHandler : IRouteHandler
    {
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            throw new NotImplementedException();
        }
    }
    
    
    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
    
    
        routes.Add(new Route("_vti_bin/Lists.asmx", new ListsHandler()));
    
    
        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
    
    
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);
    }
    
    }
  4. Start the application and navigate to http://localhost:1505/_vti_bin/Lists.asmx

  5. System.NotImplementedException: The method or operation is not implemented
Darin Dimitrov
Humm, the only difference I see is that you define the route handler in Global.asax.cs where I had it in a separate ListHandler.cs file in a Views\Serices folder. Strange ...
Philipp Schmid
Philipp Schmid