asp.net webforms 路由:可选参数 [英] asp.net webforms routing: optional parameters

查看:27
本文介绍了asp.net webforms 路由:可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的路由表中添加可选参数.例如,我希望用户浏览这样的产品目录:http://www.domain.com/browse/by-category/electronics/1,2,3

I want to add optional parameters in my routing table. For example I would like the users to browse a product catalog like this: http://www.domain.com/browse/by-category/electronics/1,2,3 etc

现在我已经创建了这样的路线:

Now i've created a route like this:

            routes.MapPageRoute(
           "ProductsBrowse",
            "browse/{BrowseBy}/{Category}",
            "~/Pages/Products/Browse.aspx"
        );

问题在于,当用户输入 http://www.domain.com/browse 时,我希望他们展示一个不同的页面,他们可以在其中选择浏览方式.所以参数 {BrowseBy} 和 {Category} 不会被使用.

Problem however is that when a user enters http://www.domain.com/browse , I would like them to present a different page where they can pick the manner on how to browse. So the parameters {BrowseBy} and {Category} will not be used.

有没有办法解决这个问题,然后为每个场景创建单独的路由?

Is there a way around this then to create seperate routes for each of the scenarios?

感谢您的时间!亲切的问候,标记

Thank you for your time! Kind regards, Mark

推荐答案

我只想创建单独的路由.

I'd just create the separate route.

也就是说,您可以根据您定义的某些约定定义一个自定义 RouteHandler,自动发送这些特殊情况,就像您有不同的路由一样.

That said, you could define a custom RouteHandler that based on some convention you define, automatically send those special cases as if you had a different route.

或者,您可以将自定义 RouteHandler 与约定一起使用,以避免必须在路由中指定特定页面.这相当于 asp.net MVC 所做的.

Alternatively you could use the custom RouteHandler along with a convention, to avoid having to specify the specific page in your routes. That's the equivalent of what asp.net MVC does.

这篇关于asp.net webforms 路由:可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆