2020-10-20 16:20:38 +03:00
|
|
|
using System;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
|
namespace MalwareMultiScan.Shared.Attributes
|
|
|
|
{
|
|
|
|
public class UrlValidationAttribute : ValidationAttribute
|
|
|
|
{
|
|
|
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
|
|
|
{
|
|
|
|
var uri = (Uri) value;
|
2020-10-20 17:08:40 +03:00
|
|
|
|
2020-10-26 16:20:47 +02:00
|
|
|
if (uri == null || !uri.IsAbsoluteUri || uri.Scheme != "http" && uri.Scheme != "https")
|
|
|
|
return new ValidationResult("Only http(s) absolute URLs are supported");
|
2020-10-20 17:08:40 +03:00
|
|
|
|
2020-10-20 16:20:38 +03:00
|
|
|
return ValidationResult.Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|