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
|
|
|
{
|
2020-10-26 21:24:40 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Validate URI to be an absolute http(s) URL.
|
|
|
|
/// </summary>
|
|
|
|
internal class IsHttpUrlAttribute : ValidationAttribute
|
2020-10-20 16:20:38 +03:00
|
|
|
{
|
2020-10-26 21:24:40 +02:00
|
|
|
/// <inheritdoc />
|
2020-10-20 16:20:38 +03:00
|
|
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
|
|
|
{
|
2020-10-26 21:24:40 +02:00
|
|
|
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 17:08:40 +03:00
|
|
|
|
2020-10-20 16:20:38 +03:00
|
|
|
return ValidationResult.Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|