开发者

Add the path _vti_bin/Lists.asmx to an ASP.NET MVC 2 web application

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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜