开发者

Keep locale in session or send along with form?

I'm refactoring 开发者_开发百科a CMS I build. The CMS has the ability to edit pages based on the chosen locale. I keep this chosen locale in a session while the user of the CMS browses through pages they like to edit.

Now, my question is:

If a user is editing a page and wants to submit changes, do you feel that I should include the locale as a hidden field in the form that is to be submitted? Just to be on the safe side? Or should I just rely on the locale that is present in the session?


Yes, you should absolutely post it along every time, because the user could have changed the locale while editing the page. The result would be that a page gets overwritten with the contents from a different locale.

If the user is not allowed to edit pages outside their locale, you will have to additionally check whether the user is allowed to edit the page/locale combination specified (because they could fake it when it comes through a session).


It depends on what you want the behaviour of the back button to be.

If a user visits a few pages, then chooses a different locale, then hits back, do wish the change of locale to be undone by the back button?

  • If so store it in a hidden field or query string
  • Otherwise store it in a cookie or a data store that is indexed by a cookie (e.g the session-state)

(If you wish a book mark page (favourite) to remember the locale then you must store it in the URL, normally as a query string.)


If you don't expect the user to switch locales, as Pekka suggests, you can determine the locale from the Request. The browser will send that information to you with every request.

I would compare the value in the request to the value in session and watch for changes. What logic you use to handle changes is up to you and flexible.

I'm not sure about your language of choice, but in ASP.NET, you can get languages from the HttpRequest.UserLanguages property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜