I have a class for Validation which is:
public class PageValidation:ValidationAttribute
{
private readonly string UserKey;
private readonly HttpContext _context;
public PageValidation(IHttpContextAccessor contextAccessor,string UserKey)
{
this.UserKey = UserKey;
_context = contextAccessor.HttpContext;
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var ActiveUserString = _context.Session.GetString("ActiveUserSession");
var ActiveUser = JsonSerializer.Deserialize<UserModel>(ActiveUserString);
if (ActiveUser.AuthCheck(UserKey)) return ValidationResult.Success;
else throw new ApplicationException("Erişim yetkiniz yok!");
}
}
And I want to call this from my controller which is:
[PageValidation(null, "Company")]
public IActionResult CompanyAndDepartments(string ViewType)
The problem is I cant send first parameter of PageValidation’s cunstructor correctly. As you see it is null and it gives me error.