且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在应用程序(.NET Core)中在Azure AD B2C中设置ui语言环境登录

更新时间:2023-02-16 11:28:34

有两种支持本地化的方法:

There's two ways to support localization:

  • 让B2C根据用户的浏览器设置提供适当的语言.为此,您无需传递ui_locales参数,只需定义您要支持的语言,B2C会为您做正确的事情.

  • Let B2C serve the appropriate language based on the user's browser settings. For this, you shouldn't need to pass a ui_locales parameter, just enable localization, define the languages you want to support and B2C will do the right thing for you.

或者,您可以通过在授权请求中发送 ui_locales 查询字符串参数来明确告知B2C服务哪个语言环境,例如: ui_locales = zh-cn 代码>

Alternatively, you can explicitly tell B2C which locale to serve up by sending the ui_locales query string parameter in your authorization request, for example: ui_locales=en-us

完整示例:

  • 法语(添加ui_locales = fr-fr):西班牙语(添加ui_locales = es-es):

    Spanish (add ui_locales=es-es): https://login.microsoftonline.com/te/tdlrv2.onmicrosoft.com/b2c_1_susi/oauth2/v2.0/authorize?client_id=1fc82d11-53ed-45e9-ba60-82797f1c0f82&redirect_uri=https%3a%2f%2ftdlrb2c.azurewebsites.net%2f&response_mode=form_post&response_type=id_token&scope=openid&ui_locales=es-es

    在C#和ASP.Net中,执行此操作的一种方法是在 OnRedirectToIdentityProvider 事件中添加查询字符串参数(请参见

    In C# and ASP.Net, one option to do this is by adding the query string parameter in the OnRedirectToIdentityProvider event (see this example, though the event is used for something else, you'd use the same pattern).