ASP.net 路由和全球化

发布于 2024-12-19 03:27:52 字数 746 浏览 3 评论 0原文

以下文件:

~/Admin/Dashboard.aspx
~/Admin/Welcome.aspx

路由

administrator/{culture}/dashboard/
administrator/{culture}/welcome/
administrator/dashboard/ (for invariant culture)
administrator/welcome/ (for invariant culture)

作为SiteMap

/administrator/dashboard/
/administrator/welcome/

来自站点地图的信息被加载到树控件中。

场景

用户从列表控件中选择法语作为所需语言,该语言保存在会话中。

问题

如何在导航(树形控件)中体现变化?

administrator/fr/dashboard/
administrator/fr/welcome/

我正处于基页面类中的 InitializeCulture() 事件的中间。我本可以使用 Response.Redirect 并对树的数据绑定事件执行丑陋的查找和替换,但这一定不是这样做的正确方法。

非常感谢评论。

The following files:

~/Admin/Dashboard.aspx
~/Admin/Welcome.aspx

are routed as

administrator/{culture}/dashboard/
administrator/{culture}/welcome/
administrator/dashboard/ (for invariant culture)
administrator/welcome/ (for invariant culture)

SiteMap

/administrator/dashboard/
/administrator/welcome/

The information from site map is loaded into a tree control.

Scenario

A user chooses French as desired language from a list control, which is saved in session.

Problem

How to reflect the change in the navigation (tree control)?

administrator/fr/dashboard/
administrator/fr/welcome/

I am in the middle of InitializeCulture() event in base page class. I could have used Response.Redirect and perform an ugly find and replace to tree's databind event, but that must not be a proper way to do so.

Comments are more than appreciated.

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

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

发布评论

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

评论(1

2024-12-26 03:27:52

好问题。站点地图和 URL 重写(路由)效果不佳。

[1] 实现一个以页面路径为参数并返回正确的url重写路径的方法:

GetUrl('/Admin/Dashboard.aspx')
这将根据 url 参数和不变区域性等返回字符串 url。

[2] 在站点地图中使用普通 url。 /Admin/Dashboard.aspx

[3] 当您绑定树时,您需要使用 GetUrl 方法来更新您的网址。

如果您使用站点地图路径,也将以同样的方式处理。

这就是我在大多数项目中所做的。

Good question. Sitemaps and url rewrite (routing) doesn't play well.

[1] implement a method which can take page path as argument and returns correct url rewritten path:

GetUrl('/Admin/Dashboard.aspx')
which will return you the string url, based on the url params and invariant culture etc.

[2] in sitemap use normal urls. /Admin/Dashboard.aspx

[3] when you bind tree, you need to use GetUrl method to update your urls.

Same way if you are using sitemappaths, that will also be handled in same way.

That's how I am doing in most of the projects I have.

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