将路径 _vti_bin/Lists.asmx 添加到 ASP.NET MVC 2 Web 应用程序

发布于 2024-08-29 23:11:50 字数 1271 浏览 2 评论 0原文

我正在尝试将路径 /_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,不是到家庭控制器!

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热风软妹 2024-09-05 23:11:50

这应该有效。以下是我执行的步骤:

  1. 启动 VS2010
  2. 使用模板创建一个新的 ASP.NET MVC 2 项目
  3. 修改 Global.asax 如下所示:

    公共密封类 ListsHandler : IRouteHandler
    {
        公共 IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            抛出新的NotImplementedException();
        }
    }
    
    公共类MvcApplication:System.Web.HttpApplication
    {
        公共静态无效RegisterRoutes(RouteCollection路线)
        {
            路线.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            路线。添加(新路线(“_vti_bin / Lists.asmx”,新ListsHandler()));
    
            路线.MapRoute(
                “默认”,
                "{控制器}/{动作}/{id}",
                新{控制器=“主页”,操作=“索引”,id=UrlParameter.Optional}
            );
        }
    
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            注册路由(RouteTable.Routes);
        }
    }
    
  4. 启动应用程序并导航到 http://localhost:1505/_vti_bin/Lists.asmx

  5. System.NotImplementedException:该方法或操作未实现

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文