小编Luk*_*keP的帖子

在SwashBuckle中删除带有IOperationFilter的路由

我正在寻找一种方法,以可配置的方式使用SwashBuckle在Swagger文档中显示/隐藏WebAPI路由.添加[ApiExplorerSettings(IgnoreApi = true)]确实会隐藏路由,但每次我想要更改时我都需要重新编译.

我已经研究过创建一个IOperationFilter使用我定义的自定义属性的方法.这样我可以用a装饰路线[SwaggerTag("MobileOnly")]并检查web.config或其他东西,看看是否应该显示路线.属性定义如下:

public class SwaggerTagAttribute : Attribute
{
    public string[] Tags { get; private set; }

    public SwaggerTagAttribute(params string[] tags)
    {
        this.Tags = tags;
    }
}
Run Code Online (Sandbox Code Playgroud)

所述IOperationFilter检测所述属性被定义并且IDocumentFilter去除的路径在这里被定义:

public class RemoveTaggedOperationsFilter : IOperationFilter, IDocumentFilter
{
    private List<string> TagsToHide;

    public RemoveTaggedOperationsFilter()
    {
        TagsToHide = ConfigurationManager.AppSettings["TagsToHide"].Split(',').ToList();
    }

    public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
    {
        var tags = apiDescription.ActionDescriptor
            .GetCustomAttributes<SwaggerTagAttribute>()
            .Select(t => t.Tags)
            .FirstOrDefault();

        if (tags != null && TagsToHide.Intersect(tags).Any()) …
Run Code Online (Sandbox Code Playgroud)

c# custom-attributes asp.net-web-api swagger swashbuckle

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

实体框架 - 填充属性后运行函数

有没有办法在实体框架加载实体后填充属性?

例如 - 我有一个对象,它有几个非映射属性,我需要在实体框架加载所有其他属性后填充这些属性。我尝试将填充属性的逻辑放入构造函数中,但它在填充任何其他属性之前运行,因此它们都读取为null.

public class Planet 
{
    public Planet()
    {
        //this does not work because the Structures
        //and Ships properties return null
        GetAllResourceGatherers(); 
    }
    public int Id { get; set; }
    public ICollection<Structure> Structures { get; set; }
    public ICollection<Ship> Ships { get; set; }

    [NotMapped]
    public int GatherRate {get; private set;}

    public void GetAllResourceGatherers
    {
       var resourceGatherers = Ships.OfType<IResourceGatherer>().ToList();  
       resourceStorers.AddRange(Structures.OfType<IResourceStorer>().ToList());
       foreach (var gatherer in resourceGatherers)
       {
          gatherRate += gatherer.GatherRate;
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

为了避免导航属性未及时加载的问题,我尝试通过将方法更改GetAllResourceGatherers()为:

public …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc entity-framework lazy-loading properties

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

添加 id_token 作为声明 AspNetCore OpenIdConnect 中间件

我正在尝试IdTokenHint在发送注销请求时进行设置。在之前的Microsoft.Owin.Security.OpenIdConnect中间件中,我可以通过执行以下操作使用通知将 设置id_tokenSecurityTokenValidated方法中的声明SecurityTokenValidated

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
    ...
    Notifications = new OpenIdConnectAuthenticationNotifications
    {
        //Perform claims transformation
        SecurityTokenValidated = async notification =>
        {
            ...
            notification.AuthenticationTicket.Identity.AddClaim(new Claim("id_token", notification.ProtocolMessage.IdToken));
        },
        RedirectToIdentityProvider = async n =>
        {
            if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
            {
                var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token").Value;
                n.ProtocolMessage.IdTokenHint = idTokenHint;
             }
         }
    }
}
Run Code Online (Sandbox Code Playgroud)

使用新的中间件Microsoft.AspNetCore.Authentication.OpenIdConnect(在 ASP.NET Core RC2 中),我在尝试完成相同的事情时遇到了麻烦。我假设我应该Events像这样。

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
    ...
    Events = new OpenIdConnectEvents()
    {
         OnTokenValidated = context =>
         { …
Run Code Online (Sandbox Code Playgroud)

claims-based-identity openid-connect identityserver3 .net-core-rc2

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

有没有办法从 Identity Server 中的客户端更新 IDP 会话令牌

我正在使用 Identity Server 来实现公司应用程序的单点登录/退出。有没有什么方法可以使当客户端的 cookie 更新(通过滑动过期)时,它也会转到 IDP 并更新其会话 cookie 的过期时间?目标是即使在 IDP 会话应该过期之后,也能够在所有应用程序之间共享 1 小时的滑动过期时间。

我现在能想到实现此目的的唯一方法是创建一些中间件来检查客户端上的 cookie,如果它即将过期,则添加一个 iframe 来调用 IDP 上的端点,告诉它也更新它的 cookie。我走在正确的轨道上吗?Identity Server 中是否内置了类似的机制?如果有,端点是什么?

为了清楚起见编辑:

问题

  • 10:00 前往客户 A
    • 重定向至 IDP 并登录
    • 重定向回客户端
      • 现在,在 10:10 之前对客户端 A 和 IDP 进行会话
    • 在客户端 A 上保持活跃状态​​直至 10:15,然后前往客户端 B
    • 用户必须再次登录,因为客户端 A 站点已保持其 cookie 处于活动状态,但 IDP 已过期-这是我希望客户端 A 调用 IDP 上的幻灯片以使其会话与任何客户端保持活动状态的位置,以便我可以转到客户端 B无需再次登录

oauth-2.0 openid-connect identityserver3

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

MongoDB C# 驱动程序 - 将集合序列化为接口

由于工作中的环境限制,我正在 MongoDB 中实现一个粗略的事件源存储。我正在尝试从 Mongo 获取列表,IClientEvents如下所示:

 var events = await _db.GetCollection<IClientEvent>("ClientEvents").FindAsync(c => c.ClientId == clientId);
Run Code Online (Sandbox Code Playgroud)

当我运行上述存储库方法时,出现以下异常:

Message: System.InvalidOperationException : {document}.ClientId is not supported.
Run Code Online (Sandbox Code Playgroud)

接口IClientEvent定义为:

public interface IClientEvent
{
    Guid Id { get; set; }
    long TimeStamp { get; set; }
    Guid ClientId { get; set; }
}

public class ClientChangedEvent : IClientEvent
{
    public Guid Id { get; set; }
    public long TimeStamp { get; set; }
    public Guid ClientId { get; set; }

    public IEnumerable<Change> Changes; …
Run Code Online (Sandbox Code Playgroud)

c# interface mongodb event-sourcing mongodb-.net-driver

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

F# 使用可区分联合的基本类型

我正在学习 F# 并努力尝试使用受歧视的联合。我有一个简单的案例,我试图Map.map在类型 Map 的简单可区分联合上使用,但它说存在类型不匹配。我基本上只是想使用类型价格作为地图

这是一个简化的示例:

type Prices = Prices of Map<string, int>

let GetSalePrice (prices: Prices) = prices |> Map.map (fun k v -> (k, v * 2))
Run Code Online (Sandbox Code Playgroud)

给我这个错误:

/Users/luke/code/chronos/Chronos.Mining/Chronos.Mining.Actors/Untitled-1(22,47): error FS0001: Type mismatch. Expecting a
    'Prices -> 'a'    
but given a
    'Map<'b,'c> -> Map<'b,'d>'    
The type 'Prices' does not match the type 'Map<'a,'b>'
Run Code Online (Sandbox Code Playgroud)

鉴于我在 map 函数中所做的一切都是返回值 * 2 我不明白为什么我会收到这个错误。

f# discriminated-union

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

ngAnimate不在Angular 1.2中将ng-enter类添加到ng-view

我一直在网上寻找答案,但我似乎无法找到任何明确的答案.

问题似乎是ngAnimate指令没有添加类ng-enterng-leave路由更改时.我创建了一个测试应用程序并将该ngAnimate指令包含在应用程序中.我还创建了animate类并将该类应用于ng-view元素

我的测试应用程序的链接在这里:http://plnkr.co/edit/6qCMeIkWeXeTQyDWcu29?p = preview

javascript angularjs angularjs-directive ng-animate ng-view

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

F# 忽略模式匹配中的模式

我可能会以错误的方式思考这个问题,但我想忽略除Some案例之外的任何案例。这是我正在使用的一些示例代码,| _ -> ignore但这似乎是错误的。有没有更好或更惯用的方法来做到这一点?我正在将一些 OOP C# 代码转换为 F#,可能会出错。

match solarSystem.MinerCoords |> Map.tryFind minerId with
| Some currentMinerCoords ->
    match solarSystem.Minables |> Map.tryFind currentMinerCoords with
    | Some _ ->
        do! GetMinerActor(minerId).StopMining() |> Async.AwaitTask
    | _ -> ignore
| _ -> ignore
Run Code Online (Sandbox Code Playgroud)

f# functional-programming pattern-matching

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