如何将 ASP.Net 表单身份验证 longinUrl 全球化为多种语言?

发布于 2024-09-08 11:09:47 字数 946 浏览 4 评论 0原文

我希望有人可以帮助解决这个问题?

目前我的 ASP.Net MVC 网站使用表单身份验证,我的 web.config 设置如下:

<authentication mode="Forms">
  <forms loginUrl="en/User/Signin" timeout="2880" />
</authentication>

我们有一些路由规则,使用 url 中的前缀 /en/ 作为语言标识符,但问题是,如果有人访问我们的法语网站 www.web.com/fr/Secure/privateData 时,他们会被重定向到 www.web.com/en/User/Signin,这又将文化设置为英语。因此,登录后,用户可能需要将语言更改回法语。

不好!

因此,如果网站需要支持更多语言,那么我需要在 Web 配置中执行以下操作:

<authentication mode="Forms">
    <%if (isGerman()) { %>
        <forms loginUrl="de/User/Signin" timeout="2880" />
    <%} else if (isFrench()) {%>
        <forms loginUrl="fr/User/Signin" timeout="2880" />
    <%} else { %>
        <forms loginUrl="en/User/Signin" timeout="2880" />
    <% } %>
</authentication>

我知道你不能在 web.config 中包含代码,但这只是为了说明我想要实现的目标。任何人都可以提供一个简单的解决方案,或者他们可能已经使用的解决方案的链接吗?

多谢!

I hope someone can help with solution to this problem?

Currently my ASP.Net MVC website uses forms authentication is set up like this my web.config:

<authentication mode="Forms">
  <forms loginUrl="en/User/Signin" timeout="2880" />
</authentication>

We have some routing rules that use the prefix /en/ in the url as a identifier for the language, but the problem is that if someone is visiting our french site www.web.com/fr/Secure/privateData, they are redirect to www.web.com/en/User/Signin, which in turn sets the culture to english. So after logging in, users may need to change there language back to french.

Not good!

So if the website need to suppurt more languages, so I need to do something like this in the web config:

<authentication mode="Forms">
    <%if (isGerman()) { %>
        <forms loginUrl="de/User/Signin" timeout="2880" />
    <%} else if (isFrench()) {%>
        <forms loginUrl="fr/User/Signin" timeout="2880" />
    <%} else { %>
        <forms loginUrl="en/User/Signin" timeout="2880" />
    <% } %>
</authentication>

I know you can not have code in the web.config, but this is just to illustrate what I am trying to achieve. Could anyone provide a simple solution, or links to solutions they may already use?

Thanks alot!

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

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

发布评论

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

评论(2

深爱不及久伴 2024-09-15 11:09:47

难道您不能只全球化一个登录页面并根据语言设置显示语言字符串吗?

否则,您应该使用某种重定向,设置一个登录页面并根据该页面内的语言设置重定向到正确的页面。但是,您可能需要在配置中添加额外的代码,告诉系统登录的语言版本在身份验证模式下不受保护(您可以在 web.config 中排除/更改网站某些部分的设置),以防止无休止的攻击循环播放。

Can't you just globalize one login page and show the language strings depending on the language setting?

Otherwise you should use some kind of redirect, set one login page and redirect to the correct page depending on the language settings within that page. However you might need to add extra code to your config telling the system that the language versions of the login are not protected within the authentication mode (you can exclude/change settings for certain parts of the site in the web.config) to prevent endless looping.

不必了 2024-09-15 11:09:47

Dai,

我做了一些非常类似的事情,并且有一个基本控制器可以在正确登录时设置语言。我现在手头没有代码,但它的内容大致如下:

    public string Lang { get; private set; } // at the top of the abstact basecontroller

    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        Lang = requestContext.RouteData.Values["lang"].ToString() ?? System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
        ViewData["Lang"] = Lang;

        base.Initialize(requestContext);
    }

然后我根据需要将 Lang 变量插入路由中。我会看看是否可以找出我使用的代码,但希望以上内容足以让您理解它。

吉姆

Dai,

I do something very similar and have a basecontroller that sets the language on correct login. I dont have the code to hand right now but it's something along the lines of:

    public string Lang { get; private set; } // at the top of the abstact basecontroller

    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        Lang = requestContext.RouteData.Values["lang"].ToString() ?? System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
        ViewData["Lang"] = Lang;

        base.Initialize(requestContext);
    }

I then plug the Lang variable into the routes as required. I'll see if i can dig out the code that i use but hopefully the above will be enough to get your head around it.

jim

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