1
I am creating a Custom Attribute in a webapi to validate a value and I would like to know if you can capture this value from a GET request.
I wanted to do it that way:
[Validacao]
public Empresa consularEmpresa([FromUri]string codigo){}
Without having to pass it:
[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 up there is my example context of what I wanted to do.
For example, I need to validate an access key passed in my webapi via url and check if it is 44 digits and if the model is 55 plus first my (Attribute or Validationattribute) should validate this rule before executing my method
How is the code of
Validacao
?– Leandro Angelo