小编Min*_*v 1的帖子

IdentityServer4-如何使用mysql.data将刷新令牌存储到数据库中?

我是IdentityServer4的新手。我读到我需要实现一个IPersistedGrantStore将刷新令牌存储到PersistedGrants数据库中的表中。

当本机应用程序请求新的访问令牌时,IdentityServer日志如下:"refresh_token" grant with value: "{value}" not found in store

那是因为我正在使用持久授权存储的内存版本。因此,我需要在PersistedGrant表中存储刷新令牌。

因此,在我的startup.cs中,添加了以下行:

builder.Services.AddScoped<IPersistedGrantStore, PersistedGrantStore>();
Run Code Online (Sandbox Code Playgroud)

IPersistedGrantStore.cs

public interface IPersistedGrantStore
{        
    Task StoreAsync(CustomPersistedGrant grant);

    Task<CustomPersistedGrant> GetAsync(string key);

    Task<IEnumerable<CustomPersistedGrant>> GetAllAsync(string subjectId);        
}
Run Code Online (Sandbox Code Playgroud)

所以我有一个CustomPersistedGrant.cs

public class CustomPersistedGrant
{
    public string Key { get; set; }

    public string Type { get; set; }

    public string SubjectId { get; set; }

    public string ClientId { get; set; }

    public DateTime CreationTime { …
Run Code Online (Sandbox Code Playgroud)

persistence identityserver4 refresh-token

5
推荐指数
1
解决办法
4819
查看次数

asp.net core - 从 appsettings.json 设置 Serilog.Exceptions

我需要使用 Serilog.Exceptions 包来捕获异常。Serilog 是从 appsettings.json 读取的

{
    "Serilog": {
        "Using": [
            "Serilog.Sinks.RollingFile",
            "Serilog.Sinks.Seq"
        ],
        "WriteTo": [
            {
                "Name": "RollingFile",
                "Args": {
                    "restrictedToMinimumLevel": "Debug",
                    "pathFormat": "myPath\\log-{Date}.log"
                }
            },
            {
                "Name": "RollingFile",
                "Args": {
                    "restrictedToMinimumLevel": "Error",
                    "pathFormat": "myPath\\error-{Date}.log"
                }
            },
            {
                "Name": "Seq",
                "Args": {
                    "serverUrl": "myUrl",
                    "apiKey": "myApiKey"
                }
            }
        ],
        "Enrich": [
            "FromLogContext",
            "WithMachineName",
            "WithThreadId"
        ],
        "Properties": {
            "Application": "myApplicationName"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的startup.cs中

var logger = new LoggerConfiguration()
    .Enrich.WithExceptionDetails()
    .ReadFrom.Configuration(Configuration)
    .CreateLogger();

Log.Logger = logger;
Run Code Online (Sandbox Code Playgroud)

但这不起作用。我是否需要在 Serilog.Exceptions 包的 appsettings.json …

c# exception serilog asp.net-core-2.0 serilog-exceptions

3
推荐指数
1
解决办法
5404
查看次数

MongoDB驱动程序C#查询优化

我在mongo db doc中读到,我也可以使用LINQ,但我对此一无所知。

例如,如果我写:

var result = collection.Find(filter);
Run Code Online (Sandbox Code Playgroud)

var result = collection.AsQueryable()
              .Where(x => x.Foo == 114)
Run Code Online (Sandbox Code Playgroud)

什么是更好的?

LINQ筛选器基于整个集合吗?在获得整个收藏之前,它会进行过滤吗?还是在过滤器之前,它给了我已经过滤的集合?

c# linq performance mongodb

3
推荐指数
1
解决办法
313
查看次数