mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-24 21:42:23 +00:00
22 lines
734 B
C#
22 lines
734 B
C#
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace MalwareMultiScan.Api.Attributes
|
|
{
|
|
/// <summary>
|
|
/// Validate URI to be an absolute http(s) URL.
|
|
/// </summary>
|
|
internal class IsHttpUrlAttribute : ValidationAttribute
|
|
{
|
|
/// <inheritdoc />
|
|
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")
|
|
return new ValidationResult("Only absolute http(s) URLs are supported");
|
|
|
|
return ValidationResult.Success;
|
|
}
|
|
}
|
|
} |