如何拦截所有 Nancy 请求 [英] How to Intercept all Nancy requests
问题描述
我看过这个帖子:Nancy:我如何捕获所有请求,而不考虑动词或路径,并在 github 文章中进行了跟进.
I have seen this post: Nancy: how do I capture all requests irrespective of verb or path and followed along on the github article.
但它不起作用.我只是在我的项目中添加了一个类:
But it does not work. I have simply added a class in my project:
public class MyBootstrapper : Nancy.DefaultNancyBootstrapper
但是这个类从来没有实例化过,github文档也没有详细讨论这个.
But this class is never instantiated, and the github documentation does not discuss this in any detail.
我需要做什么才能使我的引导程序被使用?
What do I need to do to cause my bootstrapper to be used?
推荐答案
我找到了.有两种方法可以将项目添加到管道中.一个是通过派生一个 Bootstrap 类,这对我来说失败了.另一种方法是实现一个遵循 IApplicationStartup 接口的类.那行得通,这是代码:
I found it. There are two ways to add items to the pipeline. One by deriving a Bootstrap class, which failed for me. The other by implementing a class which honored the IApplicationStartup interface. That worked, and here is the code:
public class BeforeAllRequests : IApplicationStartup
{
public void Initialize(IPipelines pipelines)
{
pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx => {
if (ctx != null)
{
Log.Debug("Request: " + ctx.Request.Url);
}
return null;
});
}
}
这篇关于如何拦截所有 Nancy 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!