FoxLearn.AspNet.JsonLd 1.1.0

dotnet add package FoxLearn.AspNet.JsonLd --version 1.1.0
                    
NuGet\Install-Package FoxLearn.AspNet.JsonLd -Version 1.1.0
                    
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.AspNet.JsonLd" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FoxLearn.AspNet.JsonLd" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="FoxLearn.AspNet.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.AspNet.JsonLd --version 1.1.0
                    
#r "nuget: FoxLearn.AspNet.JsonLd, 1.1.0"
                    
#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.AspNet.JsonLd@1.1.0
                    
#: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.AspNet.JsonLd&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=FoxLearn.AspNet.JsonLd&version=1.1.0
                    
Install as a Cake Tool

🔷 FoxLearn.AspNet.JsonLd

FoxLearn.AspNet.JsonLd is a lightweight, easy-to-use .NET library that automatically injects JSON-LD structured data into your ASP.NET application. By adding JSON-LD <script> tags into your HTML <head>, search engines like Google and Bing can better understand your content—resulting in enhanced SEO, rich snippets, and improved search visibility.

🔍 Ideal for blogs, e-commerce platforms, and any ASP.NET MVC/WebForms application that aims to improve SEO with structured metadata.


✨ Key Features

  • ✅ Auto-injection of structured data (application/ld+json)
  • 🔗 Built-in support for Schema.org types
  • ⚙️ Seamless integration with ASP.NET MVC and WebForms
  • 🚫 No manual <script> tag editing
  • 🔍 Boosts SEO for better search result presentation (e.g., breadcrumbs, rich cards)

📦 Installation

Install via the .NET CLI:

dotnet add package FoxLearn.AspNet.JsonLd

Or via NuGet Package Manager

Search for FoxLearn.AspNet.JsonLd in Visual Studio’s NuGet UI.

⚙️ Getting Started

📘 ASP.NET MVC Setup

1. Update Global.asax.cs

Modify the Application_Start method:

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);

    var builder = new ContainerBuilder();

    builder.RegisterControllers(typeof(MvcApplication).Assembly);

    builder.Register<IJsonLdBuilder, JsonLdBuilder>();

    builder.Register<JsonLdActionFilter>().FilterFor<Controller>();

    builder.RegisterFilterProvider();

    DependencyResolver.SetResolver(new ContainerBuilderDependencyResolver(builder));
}

📝 This setup automatically injects JSON-LD into your HTML <head> using action filters.

Using HTML Helper Instead of Filters

If you prefer manual injection

1. Modify Your Layout File

@using FoxLearn.AspNet.JsonLd

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Html.JsonLdScript()
</head>

2. Remove Filter Registration

Remove the following lines from Application_Start:

    //builder.Register<JsonLdActionFilter>().FilterFor<Controller>();
    //builder.RegisterFilterProvider();

3. Add JSON-LD to an Action

Example: Index action in HomeController:

public class HomeController : Controller
{
    private readonly IJsonLdBuilder _jsonLdBuilder;

    public HomeController(IJsonLdBuilder jsonLdBuilder)
    {
        _jsonLdBuilder = jsonLdBuilder;
    }

    public ActionResult Index()
    {
        _jsonLdBuilder.Add(new Organization
        {
            Name = "My Company",
            Url = new Uri("https://example.com")
        });

        return View();
    }
}

📘 ASP.NET WebForms Setup

1. Install Required Packages

  • Autofac

  • Autofac.Web

  • Autofac.Mvc5

2. Update web.config

<system.webServer>
  <modules>
    <add name="ContainerDisposal" type="Autofac.Integration.Web.ContainerDisposalModule, Autofac.Integration.Web" preCondition="managedHandler"/>
    <add name="PropertyInjection" type="Autofac.Integration.Web.Forms.PropertyInjectionModule, Autofac.Integration.Web" preCondition="managedHandler"/>
  </modules>
</system.webServer>

3. Modify Global.asax.cs

public class Global : HttpApplication, IContainerProviderAccessor
{
    static IContainerProvider _containerProvider;
    public IContainerProvider ContainerProvider => _containerProvider;

    void Application_Start(object sender, EventArgs e)
    {
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        var builder = new ContainerBuilder();

        builder.RegisterAssemblyTypes(typeof(Global).Assembly)
               .Where(t => t.IsSubclassOf(typeof(System.Web.UI.Page)))
               .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);

        builder.RegisterType<JsonLdBuilder>()
               .As<IJsonLdBuilder>()
               .InstancePerRequest();

        var container = builder.Build();
        _containerProvider = new ContainerProvider(container);

        DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
    }

    void Application_BeginRequest(object sender, EventArgs e)
    {
        var contextBase = new HttpContextWrapper(Context);
        JsonLdHandler.ApplyJsonLdFilter(contextBase);
    }
}

4. Inject JSON-LD on WebForm Page

Example: Contact.aspx.cs

public partial class Contact : Page
{
    public IJsonLdBuilder JsonLdBuilder { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (JsonLdBuilder != null)
        {
            var page = new ContactPage
            {
                Name = "Contact Us"
            };

            JsonLdBuilder.Add(page);
        }
    }
}

🔐 License

This project is licensed under the MIT License. Use it freely in personal or commercial projects.

Product Compatible and additional computed target framework versions.
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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.0 140 6/19/2025
1.0.0 112 6/15/2025