Article

Building a Modular CMS with ASP.NET Core

Build a practical component-based content management system inside an ASP.NET Core application. Learn how to model pages and reusable components, validate JSON configuration, manage media and publish consistent content without turning the CMS into an unrestricted page builder.

Dec 2, 2026 13 min read
ASP.NET Core Bootstrap C# CMS JSON configuration Razor Web Development content management system e-commerce modular architecture

There is a point in the life of a website when editing the homepage stops being a development task and starts becoming an operational responsibility. A store needs to promote a new product category, change a seasonal banner or move an important section higher up the page. None of these changes should require opening a Razor view, editing markup and deploying a new version of the entire application. On the other hand, giving an administrator a completely unrestricted HTML editor can make it surprisingly easy to break a carefully designed storefront. Somewhere between a static page and an unrestricted page builder is a much more useful option: a modular content management system.

I have been exploring this approach in the context of an ASP.NET Core storefront. The idea is to let the development team define a collection of supported components, while the people managing the website decide which components appear on a page and how they are configured. A hero banner, a carousel and a product collection can all have different settings, but they follow the same editing and publishing model. This gives the site flexibility without requiring the CMS to become a visual programming environment. It also lets the existing application remain in charge of rendering, business data, security and performance.

Start with a small vocabulary of components

Before designing the database, consider the kinds of content that the website actually needs. A commercial hero may include a headline, a short description, a background image and one or two calls to action. A featured-products section may need a title, a category filter and a maximum number of items. An informational section may include formatted text and an image. These are different components because they have different purposes and constraints. Trying to represent all of them as a generic HTML fragment makes it harder to provide useful editing controls or guarantee a consistent appearance.

The component vocabulary should grow in response to real editorial requirements. I would begin with a few common types and give each a well-defined configuration model. The administrator can choose from these types when creating a page, reorder them and edit their supported settings. The developer remains responsible for the visual implementation and the features each component supports. This arrangement is especially attractive for an e-commerce site, where content should look consistent across devices and must sometimes interact with application data that should not be editable through an arbitrary block of markup.

Give pages and component instances different responsibilities

At the database level, a page represents a destination: a homepage, landing page or informational route. It might have a title, slug, search metadata, publication state and a reference to its currently published revision. A component instance belongs to a page revision and describes what appears at a particular position. It has a stable identifier, a component type, a display order and configuration data. Keeping these concepts separate allows the same component definition to be reused across pages without making all instances share the same content.

A JSON configuration column is a practical option for storing the settings of different component types. A hero might contain a heading and media reference, whereas a product collection might contain a category identifier and display limit. There is no need to add a new nullable column to the page table for every new kind of component. However, flexibility at the storage level should not become a lack of structure in the application. JSON must still be deserialized into a known configuration type, validated and handled according to the rules of the component that owns it. A schema version is also useful when those settings evolve over time.

{
  "id": "home-hero-01",
  "type": "commercialHero",
  "schemaVersion": 1,
  "sortOrder": 10,
  "settings": {
    "heading": "Find something for every occasion",
    "description": "Explore our latest collection.",
    "imageId": 482,
    "primaryActionLabel": "Browse the catalog",
    "primaryActionUrl": "/products"
  }
}

This is an illustrative configuration rather than the complete representation of a page. Notice that the image is referenced by an identifier instead of being embedded as binary data or supplied as an arbitrary external URL. The call to action is represented by separate label and destination fields. These decisions make it possible to present appropriate editing controls and validate the configuration before publication. They also allow the renderer to determine how the content should appear instead of delegating every visual decision to the person editing the page.

Create a registry that connects component behavior

A component registry is the part of the architecture that associates a known type with its implementation. Given a component type such as commercialHero, the application can locate the definition responsible for configuration validation, media references, editing and rendering. I prefer a registry to a growing series of switch statements scattered across controllers and views. Adding a component should primarily involve implementing and registering its definition, rather than searching the codebase for every place where a component type might need special handling.

Here is a simplified C# contract to illustrate the approach. The types intentionally leave room for project-specific editing and rendering behavior. A production implementation would also handle configuration versions, deserialization errors and any asynchronous checks needed for database-backed references. The registry should reject duplicate component identifiers and unrecognized types, and only registered definitions should be able to determine which view or rendering component is used. Never construct a Razor view path directly from a string supplied by an editor or imported JSON file.

public interface ICmsComponentDefinition
{
    string Type { get; }
    int SchemaVersion { get; }
    string DisplayName { get; }
    string ViewName { get; }

    IReadOnlyList<string> Validate(JsonElement settings);
    IReadOnlyCollection<long> GetMediaIds(JsonElement settings);
    object CreateViewModel(JsonElement settings);
}

public sealed record HeroSettings(
    string Heading,
    string Description,
    long ImageId,
    string PrimaryActionLabel,
    string PrimaryActionUrl);

For components that depend on live application data, such as a collection of available products, rendering may require asynchronous work through an application service. That does not mean every component needs the same collection of dependencies or that a view should start issuing arbitrary queries. A component definition can produce a typed configuration model, while a dedicated renderer or view component handles the permitted data retrieval. The important architectural decision is to keep the type identifier stable and make the responsibilities of that type explicit enough that the editing and rendering pipelines cannot accidentally disagree.

Build the editor around the configuration model

The administration interface should make common editing tasks obvious. A page editor can show the ordered collection of components, allow administrators to add a supported type and display the appropriate settings for the selected component. A commercial hero editor might offer text fields, a media picker and call-to-action settings. A product collection editor might offer a category selector and a numeric limit. The editor does not have to expose the raw JSON, and in most cases doing so would make the workflow unnecessarily difficult for the people responsible for content.

An ASP.NET Core application that already uses Razor and Bootstrap can provide this experience without introducing an entirely new frontend stack. Reuse the existing administration layout, form validation and media management controls. Reordering components may be implemented with an accessible drag-and-drop interface or ordinary move controls, but the server should validate the resulting order and verify that the affected components belong to the page being edited. The editor is only a client of the CMS. It should not be treated as the authority on which configuration values are legal or which page revisions a particular user can change.

Validation is part of the content architecture

Configuration validation should happen on the server whenever content is saved or published. A headline can have an appropriate length limit, an image reference must exist and belong to an authorized media library, and a call-to-action destination must use an allowed URL scheme or a supported internal route. A product collection should enforce a reasonable item limit. If the application supports rich-text components, sanitize the accepted HTML with a maintained sanitizer and restrict features that are not needed. Simply storing HTML and rendering it with Html.Raw can introduce security problems if the content has not been processed through an appropriate trust boundary.

It is equally important to validate the publication as a whole. An individual component may be valid while the page still contains an unsupported combination, a missing media reference or a component type that has been removed in a new application version. Define which of these conditions should prevent publication and which can be handled gracefully at render time. Avoid relying entirely on frontend controls to catch invalid settings. Configuration can arrive through imports, older clients or other application endpoints, and every path should respect the same component rules. The registry gives the CMS a natural place to centralize those rules.

Treat media references as real relationships

Images and videos often become the hardest parts of a CMS to maintain because content may reference the same asset from several places. A media identifier stored inside JSON is convenient for rendering but does not automatically create a foreign-key relationship in the database. If an administrator deletes an image that is still referenced by a published hero, the CMS could render a broken page even though the configuration itself has not changed. A media reference system should therefore understand which assets are used by which component instances and page revisions.

One useful design is to ask each component definition to extract its media identifiers and maintain a separate reference table when the configuration is saved. Store the configuration and its associated references in the same transaction so that they cannot become inconsistent. The media management interface can then determine whether an asset is in use, prevent inappropriate deletion and provide a deliberate replacement workflow. Published revisions and drafts may reference different assets, so account for both. Store image alternatives, dimensions and optimized variants where appropriate; public rendering should provide responsive media and accessible text rather than assuming that the uploaded file is ready to serve directly to every visitor.

Keep editing separate from publication

One of the most useful features of a CMS is the ability to prepare changes without immediately affecting the public website. A straightforward way to achieve this is to store a draft revision separately from the published revision. Administrators can edit and preview the draft, and publishing switches the page to a validated revision. Rather than updating publicly visible components individually as a user clicks Save, the application publishes a coherent set of content. Visitors should see either the previous version or the newly published version, not an accidental mixture of the two.

Use a transaction to coordinate publication, including any required metadata and media references. Consider optimistic concurrency for editing and publishing so that one administrator does not silently overwrite another person's recent work. Preview routes should enforce authorization and should not be indexed or cached as if they were public content. A published revision can also provide a useful rollback target when a campaign needs to be reverted. The exact revision model can be simple at first, but decide how previous versions, media references and rollback permissions will interact before assuming that a history table alone provides a complete editorial workflow.

Render components using the existing ASP.NET Core pipeline

A public page should load its published revision and resolve its component instances through the registry in display order. Each definition can produce a typed view model, which is passed to a known Razor partial or a view component. That lets the application's normal rendering conventions handle layout, encoding and responsive markup. Developers can maintain a consistent design system across the storefront while providing the editor with enough configuration to make each instance useful. Unrecognized or invalid components should produce a controlled fallback and an internal diagnostic, not an unhandled exception that prevents every other section from rendering.

Rendering performance becomes more important as the number of components grows. A homepage containing several product collections can inadvertently run the same expensive database queries repeatedly. Load shared data efficiently, consider asynchronous retrieval where appropriate and avoid introducing unnecessary network calls for each visual block. ASP.NET Core's output caching middleware can help cache suitable public responses, but the cache policy needs to account for published revisions, personalized content and changes to live product availability. A page that depends on current inventory should not remain stale merely because its editorial configuration has not changed. Establish the correct expiration and invalidation rules for each type of data.

Migrate existing pages without losing their content

An existing storefront often has a static hero or other hard-coded sections that predate the CMS. Migrating those sections requires more than creating a new component definition. Identify the current content, image references and behavior, then create equivalent component instances in the correct page revision. Make the migration idempotent so that executing it again does not duplicate the hero or overwrite content that an administrator has already customized. Decide what happens when there is no configured component yet, and remove the static implementation only after the replacement can be rendered reliably.

The verification should cover the complete lifecycle: create a component, edit its configuration, save it, reload the editor, preview the draft, publish and check the public page. Test invalid media references, unsupported configuration values and concurrent edits. Check that the static hero and the new CMS hero cannot both appear unintentionally after migration. A successful build demonstrates that the definition and renderer compile; it does not demonstrate that the administrative form actually persists a valid configuration or that publishing makes it visible to visitors. End-to-end verification is particularly important when adding a new component type to an established CMS.

Build a CMS that fits the application

What I like about the modular approach is that it does not require replacing the application that already works. The store remains responsible for products, prices, inventory and the public shopping experience. The CMS gives administrators a controlled way to manage the editorial content surrounding those features. Component definitions provide an explicit contract between editing and rendering, JSON makes the storage model flexible, and revisions make publication deliberate. Together, those pieces can support a surprisingly capable content management experience without requiring a general-purpose page-building platform.

I would start with a small registry, a reliable page editor and a handful of components that solve real problems. Invest in validation, media relationships and the draft-to-published workflow before adding dozens of visual options. As the site evolves, new components can be introduced without rewriting the existing content model or giving up control over the public experience. The objective is not to make every detail configurable. It is to make the things that change frequently easy to manage while keeping the things that need to remain consistent firmly within the application's design.