Intercept all WebApi calls before the route matching occurs

前端 未结 4 819
青春惊慌失措
青春惊慌失措 2020-12-20 23:29

I am looking for a way to intercept/grab the request being made before matching to a route. For example, I have multiple controllers and routes set up, but I want some mecha

4条回答
  •  有刺的猬
    2020-12-20 23:51

    Like Joel Etherton mentioned in the comments, I think what you are looking for is something like adding the following code in your global.asax:

    protected void Application_EndRequest()
    {
        /*
        if(HttpContext.Current.Response.StatusCode == 404)
            Debug.WriteLine("404 something something")
        if(HttpContext.Current.Response.StatusCode == 500)
            Debug.WriteLine("500 something something")
        if(HttpContext.Current.Response.StatusCode == 200)
            Debug.WriteLine("200 something something")
        */
        Debug.WriteLine($"{context.Response.StatusCode} - {request.Url.PathAndQuery}");
    }
    

    I got my inspiration from here: ASP.NET MVC 404 Error Handling

提交回复
热议问题