How to Validate a URL in C#

Cloudmersive
2 min readFeb 3, 2021

If you’re looking for a simple way to consistently validate URLs that you interact with, you’ve come to the right place. We have an API solution that will check the syntax, domain, and endpoint of a URL to ensure its safe. With phishing scams that use invalid domain names on the rise, performing these scans on a regular basis can provide a secure experience for both your organization and customer-base.

In order to begin the validation process, we will first need to install the .NET Framework SDK (.NET Core available as well):

Install-Package Cloudmersive.APIClient.NET.Validate -Version 3.0.6

With the package installed, our next step is to call the function using the following code:

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.Validate.Api;
using Cloudmersive.APIClient.NET.Validate.Client;
using Cloudmersive.APIClient.NET.Validate.Model;
namespace Example
{
public class DomainUrlFullExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new DomainApi();
var request = new ValidateUrlRequestFull(); // ValidateUrlRequestFull | Input URL request
try
{
// Validate a URL fully
ValidateUrlResponseFull result = apiInstance.DomainUrlFull(request);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling DomainApi.DomainUrlFull: " + e.Message );
}
}
}
}

As previously mentioned, you will receive a response indicating the validity of the URL syntax and domain, and whether the endpoint passed virus checks. Additionally, the function will produce a fully formed URL. If you have any questions on this or any of our other APIs, you can contact our experienced Sales team, and they will be happy to assist.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.