using System;
using System.ComponentModel.DataAnnotations;
namespace MalwareMultiScan.Api.Attributes
{
///
/// Validate URI to be an absolute http(s) URL.
///
public class IsHttpUrlAttribute : ValidationAttribute
{
///
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (!Uri.TryCreate((string)value, UriKind.Absolute, out var uri)
|| !uri.IsAbsoluteUri
|| uri.Scheme.ToLowerInvariant() != "http"
&& uri.Scheme.ToLowerInvariant() != "https")
return new ValidationResult("Only absolute http(s) URLs are supported");
return ValidationResult.Success;
}
}
}