2010-04-21 153 views
0

我想/_vti_bin/Lists.asmx路径添加到我的ASP.NET MVC 2 Web应用程序。路径_vti_bin/Lists.asmx添加到ASP.NET MVC 2的Web应用程序

我注册的路线如下:

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

其中ListHandler被定义为:

public sealed class ListsHandler : IRouteHandler 
{ 
    #region IRouteHandler Members 

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

    #endregion 
} 

但是当我开始MVC应用程序,并尝试导航到http://localhost:8888/_vti_bin/Lists.asmx,我得到一个HTTP 404错误,而不是引发的异常。

这甚至可能在MVC?我是否需要将Lists.asmx ASPX Web服务文件添加到我的项目的特定位置(我无法在Visual Studio项目中创建_vti_bin文件夹)?

更新:达林的回复启用http://localhost:8888/_vti_bin/Lists.asmx现在可以工作(唯一的区别是路由定义的顺序)。但是现在,请求默认MVC 2项目站点的“关于”页面会导致请求http://localhost:8888/_vti_bin/Lists.asmx?action=About&controller=Home,而不是家庭控制器!

显然路线的定义顺序是重要的。

+0

'_vti_bin'文件夹是否是SharePoint约定?我记得看到使用SharePoint Web服务的命名约定的文件夹? (我可能完全错了) – Ahmad 2010-04-22 06:04:18

+0

是的,它被SharePoint使用,我实际上试图模仿我的项目中的SharePoint服务接口。 – 2010-04-22 17:02:08

回答

0

这应该工作。下面是我做的步骤:

  1. 开始VS2010
  2. 使用模板
  3. 修改Global.asax中看起来像这样创建一个新的ASP.NET MVC 2项目:

    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. 启动应用程序,并导航到http://localhost:1505/_vti_bin/Lists.asmx

  5. System.NotImplementedException:该方法或操作不implemente d
+0

Humm,我看到的唯一区别是您在Global.asax.cs中定义了路径处理程序,我在View \ Serices文件夹中将其放在了单独的ListHandler.cs文件中。奇怪... – 2010-04-22 17:01:22

+0

这对_vti_bin/Lists.asmx请求有效。但是当我点击'关于'选项卡(使用默认的MVC 2项目)时,我得到的请求路由到http:// localhost:8888/_vti_bin/Lists.asmx?action =关于&controller = Home,而不是家庭控制器! – 2010-04-22 17:15:04