22 lines
734 B
C#
Raw Normal View History

2020-10-20 16:20:38 +03:00
using System;
using System.ComponentModel.DataAnnotations;
2020-10-26 17:06:29 +02:00
namespace MalwareMultiScan.Api.Attributes
2020-10-20 16:20:38 +03:00
{
/// <summary>
/// Validate URI to be an absolute http(s) URL.
/// </summary>
internal class IsHttpUrlAttribute : ValidationAttribute
2020-10-20 16:20:38 +03:00
{
/// <inheritdoc />
2020-10-20 16:20:38 +03:00
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (!Uri.TryCreate((string)value, UriKind.Absolute, out var uri)
|| !uri.IsAbsoluteUri
|| uri.Scheme != "http" && uri.Scheme != "https")
2020-10-26 17:06:29 +02:00
return new ValidationResult("Only absolute http(s) URLs are supported");
2020-10-20 16:20:38 +03:00
return ValidationResult.Success;
}
}
}