Related question: Web API action parameter is interrupted by null and http://social.msdn.microsoft.com/Forums/vstudio/en-US/25753b53-95b3-4252-b034-7e086341ad20/web-api-action-parameter -is-intermittently-null
Hello!
I am creating an ActionFilterAttribute in ASP.Net MVC WebAPI 4, so I can apply the attribute in the action methods on the controller that we need to validate the token before executing it as the following code:
public class TokenValidationAttribute : ActionFilterAttribute { public override void OnActionExecuting(HttpActionContext filterContext) {
I am trying to read the contents as a string. I tried 3 methods, as indicated in this code, and they all return empty. I know that in WebApi I can only read the contents of the request body once, so I comment on everything else in the code and try to run it to see if I get the result. The fact is that the client and even Fiddler report 315 lengths of the contents of the request. The same size also falls into the header of the server content, but when you try to read the contents, it is empty.
If I remove the attribute and make the same request, the controller will work out well, and Json deserialization will be flawless. If I put an attribute, all I get is an empty string from the content. This happens ALWAYS. Not intermittent, as they say in related matters.
What am I doing wrong? Keep in mind that I'm using ActionFilter instead of DelegatingHandler, because only the selected actions require a token check before execution.
Thanks for the help! I really appreciate that.
Yours faithfully...
Gutemberg
Gutemberg ribeiro
source share