Skip to content

Middleware Examples? #78

Answered by scottoffen
seikosantana asked this question in Q&A
Sep 27, 2021 · 2 comments · 5 replies
Discussion options

You must be logged in to vote

Yes. The easiest way to do this it to hook into the Router.BeforeRoutingAsync event handler.

In your startup class:

public void ConfigureServer(IRestServer server)
{
    // These handlers are executed in the order that they are registered
    server.Router.BeforeRoutingAsync += MyRoutingEventHandler;
}

And then somewhere else in your code:

public async Task MyRoutingEventHandler(IHttpContext context)
{
    // do whatever you want to do here
    // if you don't want to continue to the routing, then you need to send an response here
}

The other places you can hook into the request/response lifecycle are:

  • RestServer.OnRequestAsync will run when the request is received, useful if you want to…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@seikosantana
Comment options

@scottoffen
Comment options

@seikosantana
Comment options

@scottoffen
Comment options

@seikosantana
Comment options

Answer selected by seikosantana
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants