Sana Assistant (online)
Table of Contents

DomainVerificationExtension reference

Sana.Extensions.DomainVerificationExtension is an abstract class that allows a developer to implement domain verification mechanism in Sana Commerce.

Class

Properties

RequestPath

Gets the domain verification request path. The value should be unique among all other domain verification extensions and differ from standard routes.

public override string RequestPath => "/test-verification";

Methods

GetFile

The GetFile method is responsible for returning verification file in HTTP response.

CreateFile

The CreateFile protected method is responsible for creation of an instance of DomainVerificationFile verification file based either on Stream or content file path.

It supports following overloads:

Stream based method takes the following arguments:

  • stream - an instance of Stream;
  • contentType - string representation of content type;

Content file path based method takes the following arguments:

  • contentFilePath - string representation of content file path;
  • contentType - string representation of content type;

Example:

public class TestDomainVerificationExtension : DomainVerificationExtension, IConfigurable<TestDomainVerificationConfiguration>
{
    [AllowNull]
    public TestDomainVerificationConfiguration Configuration { get; set; }

    public override string RequestPath => "/test-verification";

    public override DomainVerificationFile GetFile()
    {
        if (!string.IsNullOrEmpty(Configuration.FileContent))
        {
            var stream = new MemoryStream(Encoding.UTF8.GetBytes(Configuration.FileContent));
            return CreateFile(stream, "text/plain");
        }
        else if (!string.IsNullOrEmpty(Configuration.FilePath))
            return CreateFile(Configuration.FilePath, "text/plain");
        else
            return CreateFile("/content/files/TestDomainVerification.txt", "text/plain");
    }
}

[ConfigurationKey("TestDomainVerification")]
public class TestDomainVerificationConfiguration : ExtensionConfiguration
{
    [DataType(DataType.MultilineText)]
    public string? FileContent { get; set; }

    [SanaAdminEditor(SanaAdminEditor.FileUrl)]
    public string? FilePath { get; set; }
}