小编Gre*_*egH的帖子

使用 x5c 和 x5t 参数创建 JWK 密钥

我需要生成具有以下参数的 JWK:

\n
    \n
  • \xe2\x80\x9ckty\xe2\x80\x9d:密钥类型

    \n
  • \n
  • \xe2\x80\x9ckid\xe2\x80\x9d:密钥 ID

    \n
  • \n
  • \xe2\x80\x9cuse\xe2\x80\x9d:\xe2\x80\x9csig\xe2\x80\x9d 公钥使用

    \n
  • \n
  • \xe2\x80\x9cn\xe2\x80\x9d:模数

    \n
  • \n
  • \xe2\x80\x9ce\xe2\x80\x9d: \xe2\x80\x9cAQAB\xe2\x80\x9d 公共指数

    \n
  • \n
  • \xe2\x80\x9cx5c\xe2\x80\x9d:X.509 证书链

    \n
  • \n
  • \xe2\x80\x9cx5t\xe2\x80\x9d:X.509 证书 SHA-1 指纹

    \n
  • \n
\n

笔记:

\n
    \n
  • JWK 应包含使用 RSA 算法的公钥。RSA 提供用于密钥匹配目的的密钥 ID。

    \n
  • \n
  • 应包含使用 \xe2\x80\x9cx5t\xe2\x80\x9d (X.509 SHA-1 指纹)和 \xe2\x80\x9cx5c\xe2\x80\x9d (X.509\n证书链)的 X.509 证书参数

    \n
  • \n
\n

前 5 个参数(“kty”、“kid”、“use”、“n”、“e”)相当简单,不是问题。但是,对于“x5c”和“x5t”组件,我不确定如何生成它们。看来我可以使用https://www.samltool.com/self_signed_certs.php上找到的工具创建 x509 证书,我想生成的 x509 证书将包含 x5c 参数。这是正确的吗?我如何从中生成 x5t(证书指纹)?

\n

感谢所有帮助。

\n

encryption x509certificate x509 jwt jwk

11
推荐指数
1
解决办法
2万
查看次数

GraphQL.NET:如何将根查询分成多个部分

我目前有一个使用 GraphQL 与 .net 核心后端通信的小应用程序。我目前有一个单一的根查询,这是 GraphQL 所必需的,并且正在寻找一种方法来将其分解为多个部分以便于组织。我的查询如下所示:

public class ReactToFactsQuery : ObjectGraphType
{
    public ReactToFactsQuery(IArticleService articleService,
        INewsItemService newsItemService)
    {
        Field<ArticleType>(
            name: "article",
            arguments: new QueryArguments(new QueryArgument<IntGraphType> { Name = "id" }),
            resolve: context =>
            {
                var id = context.GetArgument<int>("id");
                return articleService.Get(id);
            }
        );

        Field<ListGraphType<ArticleType>>(
            name: "articles",
            arguments: new QueryArguments(new QueryArgument<IntGraphType>() { Name = "count" }),
            resolve: context =>
            {
                var count = context.GetArgument<int?>("count");
                if (count.HasValue)
                {
                    return articleService.GetAll(count.Value);
                }
                else
                {
                    return articleService.GetAll();
                }

            }
        );

        Field<ListGraphType<NewsItemType>>(
            name: "newsItems",
            arguments: …
Run Code Online (Sandbox Code Playgroud)

asp.net .net-core graphql

10
推荐指数
1
解决办法
2136
查看次数

Blazor 路由中的多个查询字符串参数

我在当前的项目中有多个从 url 检索 1 个查询参数的工作示例,但是当尝试对多个 url 参数遵循相同的约定时,我在 chrome 调试器控制台中收到以下错误:

Error: System.InvalidOperationException: 'Router' cannot find any component with a route for '/confirmemail'.
Run Code Online (Sandbox Code Playgroud)

我的页面路由定义为:

@page "/confirmemail/{Token}/{UserId}"
Run Code Online (Sandbox Code Playgroud)

并且该@functions{...}部分包含以下属性:

[Parameter]
string Token { get; set; }
[Parameter]
string UserId { get; set; }
Run Code Online (Sandbox Code Playgroud)

我正在尝试为如下所示的 url 检索查询字符串参数:

http://localhost:50466/confirmemail?Token=SomeReallyLargeToken&UserId=SomeGuidUserId

我怎样才能做到这一点?

.net-core blazor

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

Blazor:管理环境特定的变量

如何管理客户端blazor中不同环境之间不同的访问变量?通常,由于我使用Azure来发布应用程序,因此我会将appsettings.json文件用于本地应用程序设置,然后在我的App Service的“ Azure应用程序设置”部分中为本地环境和其他环境之间的条目设置条目。

我要完成的示例:

客户端Blazor:

@functions {
    //...more code here
    await Http.PostJsonAsync<object>("http://localhost:50466/api/auth/register", vm);
}
Run Code Online (Sandbox Code Playgroud)

在已部署的Web服务器上,应将其转换为:

@functions {
    //...more code here
    await Http.PostJsonAsync<object>("http://wwww.mywebsite.com/api/auth/register", vm);
}
Run Code Online (Sandbox Code Playgroud)

因此,我正在寻找一种方法来将站点根URL存储在环境变量中,并在发布时对其进行转换。有没有Blazor-ey的方法可以做到这一点?

c# .net-core asp.net-core blazor

8
推荐指数
2
解决办法
604
查看次数

EF6 等效于 EF Core 的 QueryTrackingBehavior.NoTracking

我正在寻找一种在我的Context班级中全局禁用更改跟踪的方法。这将防止开发人员.AsNoTracking()像我们目前所做的那样忘记输入每个存储库查询。这也将防止我们.Detach()有时手动需要实体。我在 EF Core 中找到了一个解决方案,它可以执行以下操作:

public class MyContext : DbContext
{

  public MyContext() { 
    ChangeTracker.QueryTrackingBehavior = 
       QueryTrackingBehavior.NoTracking;
  }

  public DbSet<MyEntity> MyEntities {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

但是,Context实体框架 6 中的类似乎没有QueryTrackingBehavior它的ChangeTracker. 有没有办法使用实体框架 6 来实现这一点?

请注意,我已经研究过使用AutoDetectChangesEnabled = false,但由于此处概述的原因而不起作用。

感谢所有帮助。

asp.net asp.net-mvc entity-framework

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

在SaveChanges中实现历史记录跟踪覆盖

我目前正试图通过覆盖SaveChanges方法和利用反射,以通用的方式在我的应用程序中的所有表上实现历史记录跟踪.作为一个简单的例子,假设我的域对象有2个类/ dbset,每个类的历史表如下:

DbSet<Cat> Cats { get; set; }
DbSet<CatHistory> CatHistories { get; set; }
DbSet<Dog> Dogs { get; set; }
DbSet<DogHistory> DogHistories { get; set; }
Run Code Online (Sandbox Code Playgroud)

CatHistory类如下所示(DogHistory遵循相同的方案):

public class CatHistory : HistoricalEntity
{
  public int CatId { get; set; }

  public virtual Cat Cat{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的目标是保存对象时,我想在适当的历史记录表中插入记录.使用反射时,我无法克服类型差异.我目前的尝试是在下面,我似乎被困//TODO:在线上:

        var properties = entry.CurrentValues.PropertyNames.Where(x => entry.Property(x).IsModified).ToList();

        //get the history entry type from our calculated typeName
        var historyType = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(x => x.Name == historyTypeName); …
Run Code Online (Sandbox Code Playgroud)

c# reflection entity-framework

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

IdentityServer4 错误:未找到名为“ConfigurationDbContext”的 DbContext

我试图通过添加实体框架将持久性连接到我的身份服务器。目前,在尝试添加迁移时,我收到错误

未找到名为“ConfigurationDbContext”的 DbContext。

在运行迁移之前,我已经cd进入了我的 .csproj 文件所在的目录并正在运行dotnet ef migrations add InitConfigration -c ConfigurationDbContext -o Data/Migrations/IdentityServer/Configuration以尝试添加迁移。

我的Startup.cs课程如下所示:

    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            var migrationsAssembly = typeof(ApplicationDbContext).GetTypeInfo().Assembly.GetName().Name;

            services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddAspNetIdentity<ApplicationUser>()
                .AddConfigurationStore(options =>
                {
                    options.ConfigureDbContext …
Run Code Online (Sandbox Code Playgroud)

entity-framework .net-core azure-service-fabric identityserver4

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

C:从二进制文件读取字节

我目前正在尝试从二进制文件读取 256 个字节,但在运行程序时没有得到任何输出(或错误)。我有点困惑我在这件事上哪里出错了。尝试将每个读取byte为 achar并将其存储为长度为 256 的 char 数组。我已经审查了有关 SO 的类似问题,但到目前为止还没有任何运气。我的代码的简化版本如下:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]){
    FILE *binary = fopen(argv[1], "rb");
    char bytesFromBinary[256];

    fread(&bytesFromBinary, 1, 256, binary);
    printf("%s", bytesFromBinary);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c binary fopen fread

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

Blazor onclick事件从循环传入计数器

我目前正在通过Blazor的自家解决方案实现表分页,并且遇到了一些困难。麻烦的代码在下面(这是用于将分页按钮呈现在网格下方):

@for (int i = 0; i < vm.TotalPages; i++)
{
    <button id="pg-button-@i" class="btn btn-primary btn-sm" type="button" onclick="@(() => GetTablePage(i))">@i</button>
}
Run Code Online (Sandbox Code Playgroud)

请注意,在onclick事件中,我正在调用一个函数并传入i,用于表示当前循环的计数器。

GetTablePage方法如下所示:

protected async Task GetTablePage(int page)
{
    Console.WriteLine("page number: " + page);
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,每个按钮都会调用i,其长度设置为vm.TotalPages

下面是一个示例,试图使这一点更加清楚:

查看标记(注意id,每个按钮的设置都适当):

<button id="pg-button-0" class="btn btn-primary btn-sm" type="button">0</button>
<button id="pg-button-1" class="btn btn-primary btn-sm" type="button">1</button>
<button id="pg-button-2" class="btn btn-primary btn-sm" type="button">2</button>
<button id="pg-button-3" class="btn btn-primary btn-sm" type="button">3</button>
<button id="pg-button-4" class="btn btn-primary btn-sm" type="button">4</button>
<button id="pg-button-5" …
Run Code Online (Sandbox Code Playgroud)

c# single-page-application .net-core blazor

5
推荐指数
2
解决办法
1490
查看次数

Blazor:实施404找不到页面

我想实现我的应用程序内部的页面,当blazor路由器无法找到匹配的路由时出现该页面。当前,所有请求都路由到,index.html因此我无法像通常那样通过iis处理错误。如果输入无效的路由,将显示空白页(实际上是index.html)并收到控制台错误:

'Router' cannot find any component with a route for '/some/Nonexistent/Route'.

似乎我应该能够处理此问题,因为blazor路由器能够识别出没有定义与请求的路由匹配的路由,但是到目前为止,我还没有找到任何相关文档。

我该如何实施?有没有办法挂接到blazor路由器并将所有未找到的路由定向到预定义的错误路由?

我看到https://github.com/aspnet/AspNetCore/issues/5489列出了404处理程序的问题,但是我不确定这是否是比我想要做的更健壮和可以生产的东西

.net-core asp.net-core .net-core-2.0 blazor

4
推荐指数
2
解决办法
1055
查看次数