简体   繁体   中英

MVC Attribute To Intercept Outgoing Response

I use attributes in my MVC application in order to catch incoming requests and authorize the nature of them, aka the Front Controller pattern. I want to also have an attribute in my WebApi that intercepts outgoing Responses once the Server has processed the request.

I want to do this to check the Type of the object being returned by the API, to ensure there is no leaking of sensitive internal data. Whilst thorough testing should prevent this ever happening, I wanted to implement this outgoing attribute check to be doubly sure.

Are there are framework components built in to MVC to facilitate outgoing callbacks?

Many thanks for your help

You may want to look into DelegatingHandler

This sits outside of the MVC pipepline and can handle the HttpRequest as well as the response from your controller. This will give you the opportunity to preprocess the HttpRequest, or postprocess the Response from the controller, as well as handle HttpResponse separately from the controller's response

DelegatingHandler for response in WebApi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM