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
<PackageReference Include="FoxLearn.AspNet.JsonLd" Version="1.1.0" />
<PackageVersion Include="FoxLearn.AspNet.JsonLd" Version="1.1.0" />
<PackageReference Include="FoxLearn.AspNet.JsonLd" />
paket add FoxLearn.AspNet.JsonLd --version 1.1.0
#r "nuget: FoxLearn.AspNet.JsonLd, 1.1.0"
#:package FoxLearn.AspNet.JsonLd@1.1.0
#addin nuget:?package=FoxLearn.AspNet.JsonLd&version=1.1.0
#tool nuget:?package=FoxLearn.AspNet.JsonLd&version=1.1.0
🔷 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 | Versions 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. |
-
.NETFramework 4.6.1
- FoxLearn.JsonLd (>= 1.1.1)
- Microsoft.AspNet.Mvc (>= 5.2.9)
- System.Numerics.Vectors (>= 4.5.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.