问题
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
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?
回答1:
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;
});
}
}
回答2:
This worked for me (4 years later, maybe the Wiki changed since then): Bootstrapper
来源:https://stackoverflow.com/questions/34823373/how-to-intercept-all-nancy-requests