相关疑难解决方法(0)

Configuration.GetSection始终返回null

每次调用时Configuration.GetSection,Value返回对象的属性始终为null.

我的Startup构造函数

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddEnvironmentVariables();

    this.Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)

我的ConfigureServices方法

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<SqliteSettings>(opts => Configuration.GetSection("SqliteSettings").Bind(opts));

    services.AddOptions();

    services.AddMvc();
}
Run Code Online (Sandbox Code Playgroud)

我的 appsettings.json

{
  "SqliteSettings": {
    "DataSource": "C:\\db.sqlite",
    "NewDatabase": true,
    "Version": 3
  }
}
Run Code Online (Sandbox Code Playgroud)

我用来定义SqliteSettings的类

public class SqliteSettings
{
    public string DataSource { get; set; }

    public bool? NewDatabase { get; set; }

    public int? Version { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# .net-core asp.net-core

24
推荐指数
6
解决办法
2万
查看次数

IdentityServer4 如何设置服务器 cookie 过期时间

到目前为止,我已经看到了如何为客户端 webapp 的 cookie 设置过期时间(谢谢 v0id):IdentityServer4 cookie expires

IdentityServer4 实际上使用了两个 cookie——客户端 cookie 和服务器 cookie(“idsrv”)。

如果我按照此处给出的方式设置客户端 cookie 过期时间: IdentityServer4 cookie 过期时间, 那么当我关闭浏览器并返回到需要授权的客户端 webapp 页面时,我的访问被拒绝,因为浏览器会话不再具有服务器 cookie。

所以我需要一种方法来将“idsrv”cookie 过期时间设置为与客户端相同。

目前,我看到的设置服务器 cookie(它被忽略或以某种方式删除)的最佳方法是 IdentityServer4 主机 Startup.cs / ConfigureServices() 方法中的以下代码块:

services.AddIdentityServer(options =>
            {
                options.Authentication.CookieLifetime = new TimeSpan(365, 0, 0, 0);
                options.Authentication.CookieSlidingExpiration = true;
            })
Run Code Online (Sandbox Code Playgroud)

这应该将 cookie 的到期时间设置为一年后。但是,在应用程序选项卡下的 Chrome 开发人员工具 cookie 中,我看到它仍然具有 1969 年的过期过期默认日期。

我下载了 IdentityServer4 项目源,删除了 nuget 包,并将源项目添加到我的解决方案中,以便我可以通过它进行调试。

我看到它得到了我在 ConfigureInternalCookieOptions.cs / Configure() 方法中给它的到期时间。它也匹配内部的 DefaultCookieAuthenticationScheme/应用属性。我没有发现任何特定于 IdentityServer 的东西会忽略我设置的到期日期,但它仍然有 1969 年的到期日期。

编辑:我尝试将 cookie 持久设置在 IdentityServer 主机的 AccountController 中,如下所示(有趣的是,Microsoft …

cookies identityserver4

6
推荐指数
1
解决办法
7677
查看次数

标签 统计

.net-core ×1

asp.net-core ×1

c# ×1

cookies ×1

identityserver4 ×1