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

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

问题描述

我想在我的路由表中添加可选参数。
比如我想在用户浏览产品目录如下:
<一href=\"http://www.domain.com/browse/by-category/electronics/1,2,3\">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 ,我想他们喜欢present不同的页面,他们可以挑上如何浏览的方式。这样的参数{BrowseBy}和{类别}将不被使用。

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 web表单路由:可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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