如何拦截所有Nancy请求

问题描述 投票:1回答:2

[我看过这篇文章:Nancy: how do I capture all requests irrespective of verb or path,然后在github文章中关注。

但是它不起作用。我只是在我的项目中添加了一个类:

 public class MyBootstrapper : Nancy.DefaultNancyBootstrapper

但是该类从未实例化,并且github文档未对此进行任何详细讨论。

我该怎么做才能使我的引导程序被使用?

nancy
2个回答
1
投票

我找到了。有两种方法可以将项目添加到管道中。一种是通过派生Bootstrap类而失败的。另一种是通过实现尊重IApplicationStartup接口的类。可行,这是代码:

  public class BeforeAllRequests : IApplicationStartup
{
    public void Initialize(IPipelines pipelines)
    {
        pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx => {
            if (ctx != null)
            {
                Log.Debug("Request: " + ctx.Request.Url);
            }
            return null;
        });
    }
}

0
投票

这对我有用(4年后,也许Wiki从那时起改变了:Bootstrapper

© www.soinside.com 2019 - 2024. All rights reserved.