A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Change meta title in CMS depending of environment CMS12 and CMS11

Vote:
 

Hi everyone and happy new year!

I am trying to alter meta title while using CMS in order to make it clear what environment the editor/admin is using, thus minimizing changes made in wrong environment.

For example, concatinating "Optimizely CMS - Edit" with the environment name; e g "PRODUCTION - Optimizely CMS - Edit" or "INTEGRATION - Optimizely CMS - Edit" or even "DEVELOPMENT- Optimizely CMS - Edit".

For this one could suggest using environment variable ASPNETCORE_ENVIRONMENT

For the actual site I ave a quite clear idea how to do this on the actual site, already.

 

And optionally also a similar solution for CMS 11

#341379
Jan 08, 2026 10:02
Vote:
 

Could be done using a middleware.

For CMS 12

var env = app.Environment.EnvironmentName;

app.Use(async (context, next) =>
{
    var originalBody = context.Response.Body;

    using var memStream = new MemoryStream();
    context.Response.Body = memStream;

    await next();

    context.Response.Body = originalBody;
    memStream.Seek(0, SeekOrigin.Begin);

    if (context.Response.ContentType?.Contains("text/html") == true)
    {
        var html = await new StreamReader(memStream).ReadToEndAsync();

        html = html.Replace(
            "<title>",
            $"<title>[{env}] "
        );

        await context.Response.WriteAsync(html);
    }
    else
    {
        await memStream.CopyToAsync(originalBody);
    }
});

To have this working for CMS 11 / .NET Framework you'd have to add an IHttpModule. I think I've made one in the past, want me to post that as well?

#341381
Edited, Jan 08, 2026 11:47
Vote:
 

Thanks @eric I ended up doing an extension for IApplicationBuilder  using your code and calling from Startup.cs if the environment differs from Development and Production. Worked great!

 

Yes I would be interrested in the IHttpModule too  :) 

#341398
Jan 12, 2026 8:50
Vote:
 

Just a heads up that processing entire body like that (both with middleware and http module) is quite heavy work.

#341419
Jan 13, 2026 16:33
Eric Herlitz - Jan 14, 2026 7:27
Yea I figured that as well but as long as it's only for the CMS gui it should be alright.
Vote:
 

Thanks for the great discussion so far, and thanks again to Eric for the middleware example - that’s a solid starting point!

Just to add a bit more context around this pattern and some considerations when you’re implementing it:

1. Why this works

The CMS UI in CMS 12 renders HTML that includes the browser tab <title> element.

By intercepting the response body in middleware, you can inject the environment name (e.g., Development, Integration, Production) right into the <title> before it’s sent back to the browser. That’s exactly what Eric’s middleware does: it buffers the response, rewrites the title, and then writes it back.

This is a straightforward way to visually differentiate environments in the editor interface.

 

2. Performance Consideration

As Johan pointed out, this approach does involve processing the entire HTML body on the response path. That’s not free performance-wise — it means reading and rewriting the HTML for each CMS UI page request. For most editor use cases it’s acceptable, but worth noting if your environment has heavy UI traffic or very large pages.

If that becomes a concern, you could optimize by:

  • Only applying the rewrite on specific routes (e.g., /EPiServer/…)

  • Only modifying the HTML when a certain header/cookie indicates an editor session

  • Using regex to minimize string allocation instead of full ReadToEnd

 

3. IIS / On-Premise vs DXP

On DXP or Azure App Service, middleware is the right place to do this. On CMS 11 / .NET Framework, you’d replicate similar logic in an IHttpModule, which was Eric’s offer - if you still need that, it’s worth having here for those migrating older solutions.

 

4. Alternative Ideas

If you want the environment label to be more dynamic or controlled via config, you can combine this with:

  • A custom config value (e.g., AppSettings:EditorTitlePrefix)

  • An environment-aware setting that gets injected into Angular/React-based editor components

  • A CSP header that adds a visible banner in the CMS UI via JavaScript

This avoids response body rewriting entirely, but it’s more involved.

 

Hope this will helps you !

 

#341455
Jan 19, 2026 11:46
Jonas Boman - Jan 19, 2026 12:40
Did you use Chat GPT for this?
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.