You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Visual Studio的secret.json中配置多个userIds

多账号登录配置方案

当然可以把配置改成邮箱数组来支持多账号登录,具体操作如下:

1. 修改secret.json配置格式

将原来单个userId字段改成数组格式的userIds:

{
  "Init": {
    "userIds": ["email1@example.com", "email2@example.com", "myemail@gmail.com"]
  }
}

2. 调整后端代码

配置模型类修改

找到对应读取Init配置的模型类,把原来的单个字符串属性改成集合类型:

public class InitSettings
{
    // 替换原来的string UserId
    public List<string> UserIds { get; set; } = new List<string>();
}

认证逻辑调整

在登录校验的代码里,把原来判断单个邮箱匹配的逻辑,改成校验登录邮箱是否在允许的数组中:
原来的代码大概是这样:

var allowedEmail = _configuration.GetSection("Init:userId").Value;
if (inputEmail != allowedEmail)
{
    // 拒绝登录的逻辑
}

改成:

var allowedEmails = _configuration.GetSection("Init:userIds").Get<List<string>>();
if (!allowedEmails.Contains(inputEmail))
{
    // 拒绝登录的逻辑
}

3. 其他需要检查的地方

  • 如果项目里还有其他地方读取过Init:userId这个配置项(比如初始化脚本、日志埋点等),要同步改成读取userIds数组,避免出现错误。
  • 确保ASP.NET Core的配置绑定能正常解析数组,默认情况下只要模型类型匹配就没问题,不需要额外配置。

内容的提问来源于stack exchange,提问作者Bardelman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 08:34:57