MVC3 为每个请求改变文化的正确方法
我正在使用 MVC3,并且有一些改变文化的逻辑,一切都很好。我的问题是,似乎有一些地方应该进行这种更改,但我不确定哪里是最好的地方。
一些示例显示了在控制器内对每个操作进行覆盖,如下所示:
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
// code to change culture
}
而我习惯看到的更传统的方法是在 Global.asax 文件中执行此操作,如下所示:
protected void Application_BeginRequest(object sender, EventArgs e)
{
// code to change culture
}
建议在哪里执行此操作?
I am using MVC3, and have some logic for changing the culture which all works fine. My issue, is that there seems a few places where this change should be made, and I am unsure where would be the best place to do it.
Some examples show an override on each action, from within a controller like this:
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
// code to change culture
}
Whereas a more traditional way that I am used to seeing is doing it in the Global.asax file as follows:
protected void Application_BeginRequest(object sender, EventArgs e)
{
// code to change culture
}
What is the recommended place to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
global.asax 是执行此操作的 ASP.NET 正确方法。它可以跨框架(Web 表单、动态数据、MVC)工作。
global.asax is the ASP.NET correct way of doing this. It works across frameworks (webforms, dynamic data,mvc).
Application_BeginRequest
没问题。如果您在那里的线程上设置区域性,则整个 HTTP 请求将在该区域性中执行。Application_BeginRequest
is fine. If you set the culture on the thread there, the whole HTTP Request will be executed in that culture.