我正在寻找一种方法,以可配置的方式使用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) 有没有办法在实体框架加载实体后填充属性?
例如 - 我有一个对象,它有几个非映射属性,我需要在实体框架加载所有其他属性后填充这些属性。我尝试将填充属性的逻辑放入构造函数中,但它在填充任何其他属性之前运行,因此它们都读取为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) 我正在尝试IdTokenHint在发送注销请求时进行设置。在之前的Microsoft.Owin.Security.OpenIdConnect中间件中,我可以通过执行以下操作使用通知将 设置id_token为SecurityTokenValidated方法中的声明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
我正在使用 Identity Server 来实现公司应用程序的单点登录/退出。有没有什么方法可以使当客户端的 cookie 更新(通过滑动过期)时,它也会转到 IDP 并更新其会话 cookie 的过期时间?目标是即使在 IDP 会话应该过期之后,也能够在所有应用程序之间共享 1 小时的滑动过期时间。
我现在能想到实现此目的的唯一方法是创建一些中间件来检查客户端上的 cookie,如果它即将过期,则添加一个 iframe 来调用 IDP 上的端点,告诉它也更新它的 cookie。我走在正确的轨道上吗?Identity Server 中是否内置了类似的机制?如果有,端点是什么?
为了清楚起见编辑:
由于工作中的环境限制,我正在 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) 我正在学习 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 我不明白为什么我会收到这个错误。
我一直在网上寻找答案,但我似乎无法找到任何明确的答案.
问题似乎是ngAnimate指令没有添加类ng-enter或ng-leave路由更改时.我创建了一个测试应用程序并将该ngAnimate指令包含在应用程序中.我还创建了animate类并将该类应用于ng-view元素
我的测试应用程序的链接在这里:http://plnkr.co/edit/6qCMeIkWeXeTQyDWcu29?p = preview
我可能会以错误的方式思考这个问题,但我想忽略除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) c# ×3
f# ×2
angularjs ×1
asp.net-mvc ×1
interface ×1
javascript ×1
lazy-loading ×1
mongodb ×1
ng-animate ×1
ng-view ×1
oauth-2.0 ×1
properties ×1
swagger ×1
swashbuckle ×1