使用cookie检查Application_BeginRequest中的文化信息? [英] check the culture info in Application_BeginRequest using cookie?

查看:72
本文介绍了使用cookie检查Application_BeginRequest中的文化信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用asp.net C#的多语言网站项目中,我需要检查每个请求中的文化信息,因为网站内容动态地从数据库获取,此时我需要定义具体内容的哪种语言加载到网站,哪里是保存语言文化的最佳地点?饼干还是其他什么地方?哪里是检查网站语言的最佳位置?

im on a multi lingual web site project using asp.net C# , i need to check the culture info in every request because content of web site dynamically gets from database and at this point i need to define that which language of specific content load to site ,where is the best place to save the language culture ? cookie or some where else ? and where the best place to check the language of site ?

推荐答案

没有网站语言这样的东西。



任何网站都可以使用多种语言。在许多情况下,你甚至不能说出单个短语的语言,因为短语可以是两种或更多种不同语言的混合;有些单词可以是两种或多种不同语言的有效单词。如果是课程,您可以解析HTML并阅读 lang 属性的内容: http://www.w3.org/TR/html401/struct/dirlang.html [ ^ ]。



即使这些属性可用,它们也不会给你一个解决方案。此信息仅供网站作者用于技术目的:

There is no such thing as "language of a Web site".

Any site can be in many languages. In many cases, you cannot even tell the language of a single phrase, because a phrase can be a mixture of two or more different languages; and some words can be valid words in two or more different languages. If course, you can parse HTML and read the content of the lang attribute: http://www.w3.org/TR/html401/struct/dirlang.html[^].

Even if such attributes are available, they don't give you a solution. This information is only used for technical purposes by the authors of the site:



通过lang属性指定的语言信息可能由用户代理用于以各种方式控制呈现。作者提供的语言信息可能有用的一些情况包括:



  • 协助搜索引擎
  • 协助语音合成器
  • 帮助用户用于高质量排版的代理选择字形变体
  • 帮助用户代理选择一组引号
  • 帮助用户代理做出关于连字符,连字和间距的决定
  • 协助拼写检查器和语法检查器
  • 关于内容编码可以说类似的事情。根据事物的本质,内容不必具有任何特定语言。



    一般情况下,问题不仅无法解决;它甚至不能以任何有效的方式制定。您只能邀请用户以某种方式指示请求的语言,例如,通过某些列表框中的选定项目。



    -SA

    Similar thing can be said about content encoding. By the very nature of things, content does not have to have any certain language.

    In general case, the problem is not only not solvable; it cannot be even formulated in any valid way. You only can invite the users to indicate the language of the request in some way, for example, via a selected item in some list box.

    —SA


    有几种方法在使用。

    如果你想要超越网页浏览器请求的 accept-languages 标题,你可以让用户从中选择语言菜单,然后添加它以进一步请求。

    有时,您会看到像 www.yoursite.ir/fa/somepage.aspx 这样的网址。 www.yoursite.ir/en/somepage.aspx ,或查询参数如 www.yoursite.ir/somepage.aspx?lang=en

    但这种方法有一个缺点:当用户关闭浏览器时,语言信息会丢失。因此,许多站点在cookie中保留用户选择的语言(确保为cookie设置适当的 expires 标头,否则其生命周期仅限于当前会话)。

    如果您的用户必须登录该站点,您还可以将他们的选择存储在数据库中,从而根据用户ID从中检索。
    There are several approaches in use.
    If you want to go beyond the accept-languages header of the request of the web browser, you can have the user chose the language from a menu and then "add" it to further requests.
    Sometimes, you see URLs like www.yoursite.ir/fa/somepage.aspx vs. www.yoursite.ir/en/somepage.aspx, or in query parameters like www.yoursite.ir/somepage.aspx?lang=en etc.
    But this approach has a drawback: when the user closes the browser, the language information is lost. Hence many sites persist the user selected language in a cookie (make sure to set an appropriate expires header for the cookie, as otherwise its lifetime is limited to the current session only).
    If your users have to log-in into the site, you could also store their selection in the database, and thus retrieve it therefrom based on the user id.


    这篇关于使用cookie检查Application_BeginRequest中的文化信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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