首页 > 解决方案 > Individual user settings in ASP.Net Core 3.1

问题描述

I need to have bunch of settings for each user. Theese settings are same for all the users but every user can change their values. I'm looking for a good approach to create such an infrastructure. My best guess for now is table with all the settings in DB and a table with SettingId UserId and value. Not sure this is the best way tho.

标签: c#.netasp.net-core

解决方案


在 .net core 中,您还可以使用 appsettings.json 来存储如下配置:

    {
     "Users": {
              "Arun": {
                       "Id": "ArunId",
                       "Name": "ArunName"
                      },
              "Santa": {
                       "Id": "SantaId",
                       "Name": "SantaName"
                     }
              }
    }

您可以在 IConfiguration 接口的帮助下直接将它们转换为强类型对象,如下所示:

_configuration.GetSection("用户")


推荐阅读