I am creating a Custom Attribute in a webapi for validation of a value and would like to know if it can capture this value from a GET request.
I wanted to do it this way:
[Validacao]
public Empresa consularEmpresa([FromUri]string codigo){}
No need to go through this:
[Validacao("codigo")]
public Empresa consultaEpresa([FromUri]string codigo){}
Validation Code:
[AttributeUsage(AttributeTargets.All)]
public class NfeValidation:ValidationAttribute
{
public Validacao(string chave)
{
if (!string.IsNullOrEmpty(chave) && chave.Length == 44)
{
string modeloNF = chave.Substring(18,2);
if(modeloNF != "55")
{
new HttpException("Modelo de nota fiscal inválido!");
}
}
}
}
That above is my example context of what I wanted to do.
For example, I need to validate a passkey passed in my webapi via url and verify that it is in the 44 digits and if the template is 55 the first one my (Attribute or ValidationAttribute) should validate this rule before executing my method