Working with .net core 2.1 C# 7.1.
I have an API REST server.
I have the following class:
public class ActionTimingAttribute : IAsyncActionFilter
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
// do something before the action executes
DateTime execStart = DateTime.UtcNow;
var request = context.HttpContext.Request;
string payload = ""; // HERE I NEED THE PAYLOAD WITHOUT SENSITIVE DATA
//doing funky stuff
await next();
DateTime execEnd = DateTime.UtcNow;
double elapsed = (execEnd - execStart).TotalMilliseconds;
Log(payload, elapsed);
}
}
Now, I can take the payload
with new StreamReader(request.Body)
and the rest..
BUT, if I have a password field for example, I dont want the payload
to have this value. I want to change the value to '#####' for example..
I have this for a lot of requests and different requests.
For each POST
request, I have a class representing the received json...
Obviously I dont care about HttpGet.
A method in my server looks likes this (an example just for login..)
[HttpPost, Route("Auth/Login")]
public async Task<Responses.Login> Login (Requests.Login request)
I assume I need to have some sort of attribute so it would look like:
public class Login
{
public string Email {set;get;}
[SensitiveData]
public string Password {set;get;}
}
But here, I cannot make the final combination where I have the payload and I want to omit any sensitiveData.
If I had the request model, I could look on its fields and check if they are sensitive, and if so to change value in the model (assuming its wont hurt the model the controller actually receives.)
Thanks.