2010-04-21 64 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

相關問題