需要帮助在asp.net网络表单中进行路由 [英] Need help for routing in asp.net webform

查看:154
本文介绍了需要帮助在asp.net网络表单中进行路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一些重定向,例如当用户键入此www.mysite.com/label/uk或www.mysite.com/label.aspx/uk时,我的labeluk.aspx将加载或

当用户键入此www.mysite.com/label/us或www.mysite.com/label.aspx/us时,我的labelus.aspx将加载或
当用户键入此www.mysite.com/label/fr或www.mysite.com/label.aspx/fr时,将加载我的labelfr.aspx.

因此,请告诉我如何定义路由模式,例如:

I want to achieve few redirection like when user will type this www.mysite.com/label/uk or www.mysite.com/label.aspx/uk then my labeluk.aspx will load or

When user will type this www.mysite.com/label/us or www.mysite.com/label.aspx/us then my labelus.aspx will load or
when user will type this www.mysite.com/label/fr or www.mysite.com/label.aspx/fr then my labelfr.aspx will load.

So please tell me how do I define pattern for routing like:

RouteTable.Routes.MapPageRoute("Source1", "label/{ID}", "~/labeluk.aspx");

RouteTable.Routes.MapPageRoute("Source1", "label/{ID}", "~/labelus.aspx");

我无法弄清楚如何通过路由来实现它.
请帮助我形成地图路线.
谢谢

I am not being able to figure out how to achieve it by routing.
Please help me to form the map route.
Thanks

推荐答案

从我所看到的(而且我从来不需要尝试过)MSDN:路由 [ 因此,您将设置路由:
From what I can see (and I have never needed to try this) MSDN: Routing[^] you don''t do it like that: the {ID} part of your route becomes a rotuing parameter that is passed through to your target ASPX file via Page.RouteData.Values("ID") - you don''t use it to "append a region" on the end of your ASPX file name.
So you would set up a routing:
RouteTable.Routes.MapPageRoute("Source1", "label/{ID}", "~/labelSorter.aspx");

,然后根据提供的参数,在labelSorter中从那里重定向到相应的labelXX.aspx文件.

And then do a redirection in labelSorter to the appropriate labelXX.aspx file from there, depending on the parameter provided.



使用路由您上面使用的路由模式将无法解决您指定的问题.路由仅遵循指定的请求的url模式,但不能动态加载路由的页面.因此,我建议使用诸如"label-landing.aspx"之类的中间提单页面来解决您的问题.在该页面上,您可以基于ID路由值从该页面重定向用户,也可以根据ID路由值在该页面上处理请求.

您可以使用的路由模式是

Hi,
Using routing the routing pattern you used above will not solve your specified problem.Routing only follow specified requested url pattern,but cant dynamically load the routed page. So what I can suggest is to use intermediate lading page like "label-landing.aspx" to sort out your issue. On that page either you can redirect user from that page based on ID route value or you can process the request on that page based on ID route value.

The routing pattern you can use is,

RouteTable.Routes.MapPageRoute("Source1", "label/{ID}", "~/label-landing.aspx");
RouteTable.Routes.MapPageRoute("Source2", "label.aspx/{ID}", "~/label-landing.aspx");



希望这会有所帮助.



Hope this will help.


这篇关于需要帮助在asp.net网络表单中进行路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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