Skip to content

AspNet HttpContext Item Layout Renderer

Rolf Kristensen edited this page Dec 18, 2022 · 5 revisions

ASP.NET Item variable from HttpContext.Items dictionary. Useful for storing state per request basis.

Platforms Supported: All

Configuration Syntax

${aspnet-item:variable=String:objectpath=String:format=String}

Parameters

Rendering Options

  • item - Key for lookup in Items-dictionary (Required)

    Introduced with NLog.Web v5.1, and replaces the Variable-option

  • format - Format-specifier for converting the value as string (Optional)

    Introduced with NLog.Web v5.0

  • culture - Culture-specifier for converting the value as string (Optional)

    Introduced with NLog.Web v5.0

  • objectpath - Property path if the value is an object, also supports nested properties (Optional).

    Introduced with NLog.Web v5.2 and replaces EvaluateAsNestedProperties-option

Examples

You can set the value of an ASP.NET Item variable by using the following code:

Example usage of ${aspnet-item}

HttpContext.Items["myvariable"] = 123;
HttpContext.Items["stringvariable"] = "aaa BBB";
HttpContext.Items["anothervariable"] = DateTime.Now;

${aspnet-item:variable=myvariable} - produces "123"
${aspnet-item:variable=anothervariable} - produces "01/01/2006 00:00:00"
${aspnet-item:variable=anothervariable:culture=pl-PL} - produces "2006-01-01 00:00:00"
${aspnet-item:variable=myvariable:padding=5} - produces "  123"
${aspnet-item:variable=myvariable:padding=-5} - produces "123  "
${aspnet-item:variable=stringvariable:upperCase=true} - produces "AAA BBB"
Clone this wiki locally