代码之家  ›  专栏  ›  技术社区  ›  Philipp Schmid

添加路径_vti_bin/列表。asmx到ASP。NETMVC2Web应用程序

  •  0
  • Philipp Schmid  · 技术社区  · 16 年前

    我正在尝试添加路径 /_vti_bin/列表。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中可能吗?我需要添加列表吗。将asmx ASPX web服务文件保存到我的项目的特定位置(我无法在Visual Studio项目中创建_vti_bin文件夹)?

    更新: 达林的反应是有效的 http://localhost:8888/_vti_bin/Lists.asmx 现在开始工作(唯一的区别是路线定义的顺序)。但是现在,请求默认MVC2项目站点的“About”页面会导致请求 http://localhost:8888/_vti_bin/Lists.asmx?action=About&controller=Home ,而不是主控制器!

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

    1 回复  |  直到 16 年前
        1
  •  0
  •   Darin Dimitrov    16 年前

    这应该行得通。以下是我所做的步骤:

    1. 开始VS2010
    2. 创建一个新的ASP。NET MVC 2项目使用的模板
    3. 修改全局。尽快看起来像这样:

      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. 系统NotImplementedException:方法或操作未实现