代码之家  ›  专栏  ›  技术社区  ›  Josh

带有WebForms的ASP.NET路由

  •  0
  • Josh  · 技术社区  · 14 年前

    我正在尝试切换现有的webforms应用程序以使用路由,并希望分阶段执行。但是,我遇到了一些特定路线的问题:

    //I want to catch existing calls to .aspx pages, but force them through  
    // a route, so I can eventually drop the .aspx extension  
    new Route("{page}.aspx", new MyCustomRoute());
    

    这根本不起作用,就像对[somepage]的调用一样。aspx永远不会绊倒这个路由…如果我把路线改成这样:

    //Same thing sans .aspx extension
    new Route("{page}", new MyCustomRoute());
    

    所有打给[某个页面]的电话都会被接听。有什么想法吗?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Josh    14 年前

    好吧,现在我觉得自己很蠢…

    结果发现在 RouteCollection 调用的类 RouteExistingFiles 默认为假。显然,在将现有文件转换为路由之前,ASP.NET路由优先于它们,因此对现有页的任何调用显然都不会由我的路由处理。将此属性设置为true可以解决我的问题,尽管这可能会产生我尚未意识到的意外副作用。