在每个请求的路由中设置默认值
我有以下路由,这基本上使我能够将语言保留在 url 中,并确保只有 de
和 fr
(约束)是可能的。在 Default
- 路由中,如果包含的 url 中没有语言,我将 de
设置为标准:
// Routing with language
routes.MapRoute("Default_with_language", "{lang}/{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
}, new { lang = "de|fr" });
// Standard-Routing
routes.MapRoute("Default", "{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
lang = "de",
});
How can I change the default-language in every request?假设我有两个网址,一个是德语,一个是法语,如果调用的是法语网址,我希望有 lang = "fr"
...
谢谢您的任何提示 SL3DG3
I have got following routing, which basically enables me to keep the language within the url and makes sure only de
and fr
(constraint) is possible. In the Default
- Routing, I set de
as standard if there is no language in the url contained:
// Routing with language
routes.MapRoute("Default_with_language", "{lang}/{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
}, new { lang = "de|fr" });
// Standard-Routing
routes.MapRoute("Default", "{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
lang = "de",
});
How can I change the default-language in each request? Let's say I have two Urls, one in german and one in french, I would like to have lang = "fr"
if the french url is called...
Thx for any tipp
sl3dg3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的
Application_BeginRequest
处理程序中,您可以访问当前路由,并且应该能够使用类似的方法更改值。希望这足以使路由获取新值。
In your
Application_BeginRequest
handler, you can access the current route and you should be able to change the values using something like this.Hopefully, that's enough to make routing pick up the new value.
@Tim:谢谢你的回答。我同时想出了类似的东西:
sl3dg3
@Tim: Thx for your answer. I figured out something similar at the same time:
sl3dg3