I using asp.net core API and My question is
How will I access request context in custom attribute, Actually I am sending TimeZone info in request Header that I want to access here.
My C# Date validation Code is
public class DateRangeAttribute : ValidationAttribute
{
public string StartDate { get; set; }
public string EndDate { get; set; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (validationContext == null)
{
throw new ArgumentNullException();
}
return new ValidationResult("Date is not in given range.", new List<string>() {
validationContext.MemberName
});
}
}
My Model is
[DateRange(StartDate = "01/01/2000", EndDate = "12/31/9999")]
public DateTime StartWork { get; set; }