我试图确定ApiResource和Client是如何联系在一起的.
如何确保从客户端请求令牌的人请求特定的ApiResource可以访问该ApiResource?
是否被Scopes捆绑在一起?
以下是QuickStart中稍微修改过的代码:
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource("api1Resource", "My API")
{
Scopes =
{
new Scope("api1"),
new Scope("api1.ro"),
new Scope("offline_access")
},
UserClaims = { "role", "user" }
}
};
}
// client want to access resources (aka scopes)
public static IEnumerable<Client> GetClients()
{
// client credentials client, for APIs
return new List<Client>
{
new Client
{
ClientId = "apiClient",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets =
{
// Secret that can be created and given …Run Code Online (Sandbox Code Playgroud) 我有一个 .Net Core 2.2 库项目。该项目包含的所有静态文件都是将“构建操作”设置为内容的静态文件。
该项目的唯一目的是构建到 Nuget 包中,并让任何消费者将包含的内容添加到他们的wwwroot文件夹中。
不幸的是,在查看解决方案资源管理器时,这些文件“似乎”就在那里,但它们的实际路径是:
C:\Users\MyName\.nuget\package\mylib.staticfiles\0.0.1\contentFiles\any\netcoreapp2.2\wwwroot.
在我的库中,我在 .csproj 文件中使用以下内容:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<PackageVersion>0.0.6</PackageVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="wwwroot\**" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
很难找到有关如何完成此操作的文档。任何帮助表示赞赏。
用户界面允许用户选择一个或多个标签。我想选择所有具有用户输入的所有标记相关联的节点,而不仅仅是单个标记。
public JsonResult SearchNodesByTags(string[] tags)
{
var dbTags = _DbContext.Tags.Where(t => tags.Contains(t.DisplayName)).ToList();
var nodes = _DbContext.Nodes.Where(n => n.Tags.Intersect(dbTags).Any());
// Error about intersection with non primitive
return Json(nodes);
}
Run Code Online (Sandbox Code Playgroud) 我有一个BaseClass,它是抽象的,并且有许多抽象属性.
我有十几个(可能会增长)实体,它们是Entity Framework的一部分,每个实体都派生自BaseClass.
我试图避免不得不这样做:
modelBuilder.Entity<Entity1>().HasKey(t => t.Id);
modelBuilder.Entity<Entity2>().HasKey(t => t.Id);
modelBuilder.Entity<Entity3>().HasKey(t => t.Id);
...
Run Code Online (Sandbox Code Playgroud)
对于每个属性和每个实体,因为这看起来非常浪费并且会产生大量的代码重复.我尝试通过以下方式获取从BaseClass派生的名称空间中的所有实体:
var derivedEntities = Assembly.GetExecutingAssembly().GetTypes().
Where(t => t.Namespace == "My.Entities" && t.IsAssignableFrom(typeof(BaseClass)));
Run Code Online (Sandbox Code Playgroud)
但是,接下来的逻辑步骤似乎是:
foreach (var entity in derivedEntities)
{
modelBuilder.Entity<entity>().HasKey(t => t.Id);
}
Run Code Online (Sandbox Code Playgroud)
但是不会编译,因为
"实体是一个变量,但就像一个类型一样使用".
我正在为我的控制器 (ASP.NET Core) 编写测试,并收到一些 JSON。我现在想将其反序列化为正确的对象,以便我可以对返回的数据进行一些断言。反序列化期间没有抛出异常,但我的Data变量为空。
这是用于反序列化的代码:
var output = JsonConvert.DeserializeObject(responseString,
typeof(CrudOperationResult<IEnumerable<ApiResource>>));
Run Code Online (Sandbox Code Playgroud)
这是 CrudOperationResult 类:
public class CrudOperationResult<T>
{
private CrudOperationResult()
{ }
private CrudOperationResult(CrudResult result, string errorMessage, T data)
{
Result = result;
ErrorMessage = errorMessage;
Data = data;
}
[JsonIgnore]
public CrudResult Result { get; private set; }
public bool IsError
{
get
{
return Result == CrudResult.Error;
}
}
public string ErrorMessage { get; private set; }
public T Data { get; private set; }
} …Run Code Online (Sandbox Code Playgroud) 我在网上看到了几篇关于为什么应该使用 bufio.Scanner 而不是 bufio.Reader 的宣传片。
我不知道我的测试用例是否相关,但是在从文本文件中读取 1,000,000 行时,我决定测试一个与另一个:
package main
import (
"fmt"
"strconv"
"bufio"
"time"
"os"
//"bytes"
)
func main() {
fileName := "testfile.txt"
// Create 1,000,000 integers as strings
numItems := 1000000
startInitStringArray := time.Now()
var input [1000000]string
//var input []string
for i:=0; i < numItems; i++ {
input[i] = strconv.Itoa(i)
//input = append(input,strconv.Itoa(i))
}
elapsedInitStringArray := time.Since(startInitStringArray)
fmt.Printf("Took %s to populate string array.\n", elapsedInitStringArray)
// Write to a file
fo, _ := os.Create(fileName)
for i:=0; i < …Run Code Online (Sandbox Code Playgroud) 我想定义一条只需要匹配前几个段的路线,并忽略其余部分:
[Route("public/portfolio/{publicPortfolioId}")]
Run Code Online (Sandbox Code Playgroud)
这个想法是任何以 开头的内容public/portfolio/myid都会匹配。这应该会导致匹配:
public/portfolio/myid
public/portfolio/myid/something
public/portfolio/myid/something/that/doesnt/exist
Run Code Online (Sandbox Code Playgroud) 我有我一直在使用的扩展方法。直到最近,我才知道EF Core 2.x默认执行混合评估,这意味着对于它不知道如何转换为SQL的事情,它将从数据库中提取所有内容,然后执行内存中的LINQ查询。此后,我禁用了此行为。无论如何,这是我的扩展方法:
public static class RepositoryExtensions
{
public static IQueryable<T> NonDeleted<T>(this IQueryable<T> queryable) where T : IDeletable
{
return queryable.Where(x => !x.Deleted);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,实体框架会引发异常,并带有以下消息(因为我此时已配置了它,而不是从数据库中获取所有内容并在本地进行评估):
警告“ Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning”生成的错误:LINQ表达式“其中Not(Convert([x],IDeletable).Deleted)”无法翻译,将在本地进行评估。通过将事件ID'RelationalEventId.QueryClientEvaluationWarning'传递到'DbContext.OnConfiguring'或'AddDbContext'中的'ConfigureWarnings'方法,可以抑制或记录此异常。
这种扩展方法在很多地方都在使用,所以我宁愿修复if并使它起作用(在数据库中评估),而不是去跨多个项目删除它,然后用代替.Where(x => !x.Deleted)。
是否还有其他人遇到过这种情况,并且知道如何制作在数据库中评估的IQueryable扩展(在运行时转换为SQL)?在将LINQ转换为SQL时,似乎EF只是在查看具体的类?
更新:评论之一要求一个示例。做一些额外的测试,我可以看到这是应用于从EF Core返回的IQueryable时.FromSql。如果.NonDeleted()直接应用于实体Organization,则似乎可以正常工作。
// Service layer
public class OrganizationService
{
public IEnumerable<Data.Entities.Organization> GetAllForUser(int? userId)
{
return _repository.GetOrganizationsByUserId(userId.GetValueOrDefault()).NonDeleted();
}
}
Run Code Online (Sandbox Code Playgroud)
//储存库层
using PrivateNameSpace.Common.EntityFramework;
using PrivateNameSpace.Data.DbContext;
using PrivateNameSpace.Data.Repos.Interfaces;
using Microsoft.EntityFrameworkCore;
using System.Data.SqlClient;
using System.Linq;
public class OrganizationRepository: Repository<Entities.Organization, int, OrganizationContext>, IOrganizationRepository
{
private …Run Code Online (Sandbox Code Playgroud) 我在尝试确定如何使我的序列化能够正确访问单个结果以及数组时遇到困难。
当我进行 REST 调用在服务器上查找某些内容时,有时它会返回模型数组,但如果搜索结果只有一个模型,则不会作为错误返回。这是当我收到无法反序列化的异常时,因为对象属性需要一个数组,但接收的是单个对象。
有没有办法定义我的类,以便它可以在返回时处理类型为 ns1.models 的单个对象而不是对象数组?
[JsonObject]
public class Responses
{
[JsonProperty(PropertyName = "ns1.model")]
public List<Model> Model { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
可反序列化的响应:
{"ns1.model":[
{"@mh":"0x20e800","ns1.attribute":{"@id":"0x1006e","$":"servername"}},
{"@mh":"0x21a400","ns1.attribute":{"@id":"0x1006e","$":"servername2"}}
]}
Run Code Online (Sandbox Code Playgroud)
无法序列化的响应(因为 JSON 仅包含单个“ns1.model”):
{"ns1.model":
{"@mh":"0x20e800","ns1.attribute":{"@id":"0x1006e","$":"servername"}}
}
Run Code Online (Sandbox Code Playgroud)
例外:
Newtonsoft.Json.JsonSerializationException was unhandled HResult=-2146233088 Message=Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[ConsoleApplication1.Model]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized …Run Code Online (Sandbox Code Playgroud) 这看起来好像我在这里圈,也许是因为使用了这么多订阅并且必须将它们链接在一起.
我希望能够刷新令牌,如果它已使用刷新令牌过期.这就是我所拥有的,如果可能的话,我真的很感激一个简单的工作示例.
总之,我如何确保AudienceService首先检查令牌是否有效,如果没有,它会尝试使用刷新令牌刷新它,然后使用适当的令牌调用端点?
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { Http, RequestOptions } from '@angular/http';
import { ConfirmDialogModule, ListboxModule, PickListModule } from 'primeng/primeng';
import { AppComponent } from './app.component';
import { HeaderComponent } from './components/header/header.component';
import { HomeComponent } from './components/home/home.component';
import { ListAudiencesComponent } from './components/audiences/list-audiences/list-audiences.component';
import { AudienceService } from './services/audience.service'; …Run Code Online (Sandbox Code Playgroud)