OWIN Self host - connect to the start of the request, completion request events

In the ASP.NET OWIN native host, how do you connect to the BeginRequest, EndRequest, Application Start, and Application End events since there is no need for Global.asax.cs?

+4
source share
2 answers

Add a simple owin middleware at the beginning of the pipeline to handle the start and end request.

public class SimpleMiddleWare:OwinMiddleware
{
    public SimpleMiddleWare(OwinMiddleware next) : base(next)
    {
    }

    public override async Task Invoke(IOwinContext context)
    {
        Debug.WriteLine("Begin Request");//Add begin request logic
        await Next.Invoke(context);
        Debug.WriteLine("End Request");//Add end request logic
    }
}
+4
source

In WebAPI you can use filters . You can override OnActionExecutingand OnActionExecuted. If you do not want to comment on each individual controller, you can add your filter as a global filter:

GlobalConfiguration.Configuration.Filters.Add(new MyFilterAttribute());

ApplicationStart OwinStartup. , - ApplicationEnd.

+1

All Articles