Umbraco.Community.ServerVariables 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Umbraco.Community.ServerVariables --version 0.2.0
                    
NuGet\Install-Package Umbraco.Community.ServerVariables -Version 0.2.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="Umbraco.Community.ServerVariables" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Umbraco.Community.ServerVariables" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Umbraco.Community.ServerVariables" />
                    
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 Umbraco.Community.ServerVariables --version 0.2.0
                    
#r "nuget: Umbraco.Community.ServerVariables, 0.2.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 Umbraco.Community.ServerVariables@0.2.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=Umbraco.Community.ServerVariables&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Umbraco.Community.ServerVariables&version=0.2.0
                    
Install as a Cake Tool

Server Variables for Umbraco

This package reintroduces server variables in Umbraco 15+, which is a way to expose variables from C# to JavaScript.

What is it?

Server Variables was a thing up until Umbraco 13, where you could add variables to your site through the ServerVariablesParser.Parsing notification and access them in the Backoffice through Umbraco.Sys.ServerVariables. This was removed in Umbraco 14, but this package reintroduces the concept with a twist.

In short, this package gives you a simple way to expose server variables to your Umbraco Backoffice and/or Frontend. It allows you to add server variables to your site without having to write any or only a little code.

The variables are added through appsettings.json or through the IServerVariablesService interface.

The twist is that the variables are made available through the importmap in the browser. This way, you can import the variables where you need them without having to rely on any global JavaScript objects. They will also work in the Frontend which is a big plus.

The variables are added either through appsettings.json or through the IServerVariablesService interface and are accessed through an importmap in the browser:

import vars from 'vars';

console.log(vars); // { apiUrl: 'https://api.example.com' }

NB! Do not include any secrets in the server variables as they will be exposed to the public.

Requirements

  • Umbraco 15 or higher
  • .NET 9 or higher

Usage

See the documentation for more information on how to use the package:

Acknowledgements

Javascript icons created by Graphix's Art - Flaticon

Product Compatible and additional computed target framework versions.
.NET 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
0.4.0 142 3/15/2025
0.3.0 163 3/12/2025
0.2.0 171 3/10/2025
0.1.0 174 3/9/2025