When you have a service that users can use on their website, and you want to verify the site ownership. Ownership verification means proving to your platform that the user owns a specific website.
Ex. Google ask to verify your website when linking to Google Search Console
How To Verify site ownership?
Verify ownership of a site by uploading a special HTML file to a specific location on your site. This file is tied to a specific user.
Pre-Requisites
The Code
Part 1: Create the verficatonCode
GetVerifyFileInfo() will return the information to create the file.
The layout part is only to showcase what you can show to the user
using CodeHelper.Tools.VerifyWebsite;
WebSiteHelper _verifier = new() { WebsiteUrl = "https://thedomain.com" };
//-- Get the fileName, fileUrl and fileContent
var (verifyFileName, verifyFileUrl, verifyContent) = _verifier.GetVerifyFileInfo();
//-- Save the contentCode (which will be needed in the second part )
var _saveVerifyCode = _verifier.VerifyCode; //-- Save this code
//-- Layout (Use the variables to return the information to the user)
Console.WriteLine("Copy the html file to the root of your website");
Console.WriteLine("Filename: " + verifyFileName);
Console.WriteLine("Content: " + verifyContent);
Console.WriteLine(Environment.NewLine);
Console.WriteLine($"Check that {verifyFileUrl} is accessible");
Console.WriteLine($"Click Verify WebSite");
Part 2: The user has copied the file to the root directory of the domain
_verifier = new() { WebsiteUrl = "https://thedomain.com",
VerifyCode = _saveVerifyCode };
if (await _verifier.VerifyWebSite())
Console.WriteLine("Your website is verified"); //-- Your Next Code
else
Console.WriteLine("We could not verify your website");
Next (Roadmap)
- Function to download the file directly.
- Verification via meta tag
- Verification via DNS
Don't forget to follow me for updates
Check out my all my NuGet Packages
Top comments (0)