FoxLearn.AspNetCore.JsonLd 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package FoxLearn.AspNetCore.JsonLd --version 1.0.1
                    
NuGet\Install-Package FoxLearn.AspNetCore.JsonLd -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FoxLearn.AspNetCore.JsonLd" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FoxLearn.AspNetCore.JsonLd" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="FoxLearn.AspNetCore.JsonLd" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FoxLearn.AspNetCore.JsonLd --version 1.0.1
                    
#r "nuget: FoxLearn.AspNetCore.JsonLd, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FoxLearn.AspNetCore.JsonLd@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FoxLearn.AspNetCore.JsonLd&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=FoxLearn.AspNetCore.JsonLd&version=1.0.1
                    
Install as a Cake Tool

FoxLearn.AspNetCore.JsonLd

It's a lightweight .NET library that automatically inserts <script> tags with the MIME type application/ld+json into the <head> section of your HTML. This helps search engines better understand your web pages by adding structured data (JSON-LD), which can improve SEO and enhance how your content appears in search results.


Features

  • 🤖 Automatically injects structured data (JSON-LD)
  • 🔍 Enhances SEO and search visibility
  • ⚙️ Easy integration with ASP.NET Core applications
  • 🧩 Supports custom schema definitions using Schema.org formats
  • ✨ No manual HTML edits required

Installation

Install via the .NET CLI:

dotnet add package FoxLearn.AspNetCore.JsonLd

Or via the NuGet UI in Visual Studio by searching for FoxLearn.AspNetCore.JsonLd

Usage

Register the services in Startup.cs or Program.cs:

builder.Services.ConfigureJsonLd<FoxLearn.JsonLd.Schema.Organization>(options =>
{
    options.Name = "FoxLearn";
    options.Url = new Uri("https://foxlearn.com");
    options.LegalName = "FoxLearn";
    options.Logo = new Uri("https://foxlearn.com/img/logo.png");
    options.Description = "Welcome to foxlearn.com! This site is a blog about everything that matters in the world of programming.";
    options.ContactPoint = new List<ContactPoint>()
    {
        new ContactPoint() { ContactType = "Customer Service", Name = "Tan Lee", Email = "example@gmail.com"}
    };
    options.Founder = new List<IPerson>()
    {
        new Person() { Name = "Tan Lee"}
    };
    options.FoundingDate = new FoxLearn.JsonLd.Date(2016, 01, 01);
    options.Email = "example@gmail.com";
});

// You can easily configure JSON-LD serialization options here.

builder.Services.Configure<JsonLdOptions>(options =>
{
    options.SerializerOptions.WriteIndented = true;
});

builder.Services.AddScoped<IJsonLdBuilder, JsonLdBuilder>(); // Required

var app = builder.Build();

...

app.UseHttpsRedirection();
app.UseRouting();

app.UseAuthorization();

app.MapStaticAssets();

app.UseJsonLd();

// Or you can configure JSON-LD serialization options as shown below.
//app.UseJsonLd(options =>
//{
//    options.SerializerOptions.WriteIndented = true;
//});

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}")
    .WithStaticAssets();

Add structured data in your controller or view model:

private readonly IJsonLdBuilder _jsonLd;

public HomeController(IJsonLdBuilder jsonLd)
{
    _jsonLd = jsonLd;
}

public IActionResult Category(string categoryName)
{
    BreadcrumbList breadcrumbList = new()
    {
        Name = "Breadcrumb",
        ItemListElement = new List<IListItem>()
        {
            new ListItem { Position = 1, Name = "Home", Url = new Uri($"{Request.Scheme}://{Request.Host}") },
            new ListItem { Position = 2, Name = "Category", Url = new Uri($"{Request.Scheme}://{Request.Host}/{categoryName}") }
        }
    };

    _jsonLd.Add(breadcrumbList);
    return View();
}

Example Output

<script type="application/ld+json">
{
  "@context":"https://schema.org",
    "@type": "Organization",
    "email": "example@gmail.com",
    "founder": {
      "@type": "Person",
      "name": "Tan Lee"
    },
    "foundingDate": "2016-01-01",
    "legalName": "FoxLearn",
    "contactPoint": {
      "@type": "ContactPoint",
      "email": "example@gmail.com",
      "contactType": "Customer Service",
      "name": "Tan Lee"
    },
    "logo": "https://foxlearn.com/img/logo.png",
    "url": "https://foxlearn.com",
    "name": "FoxLearn",
    "description": "Welcome to foxlearn.com! This site is a blog about everything that matters in the world of programming."
}
</script>

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 146 6/18/2025
1.1.0 161 6/14/2025
1.0.4 251 6/13/2025
1.0.3 285 6/12/2025
1.0.2 282 6/12/2025
1.0.1 237 6/9/2025
1.0.0 98 6/6/2025