Skip to content

Commit 60c6e2d

Browse files
committed
Release v1.1.0 – Remove System.Web.Helpers dependency, improve XSS safety, add version sync
- Replaced Json.Encode() with HttpUtility.JavaScriptStringEncode() to eliminate dependency on System.Web.Helpers - Removed all external dependencies; library now uses only System + System.Web - Improved XSS sanitization logic and ensured consistent safe console output - Cleaned unused references in .csproj - Added Version 1.1.0 + AssemblyVersion 1.1.0.0 + FileVersion 1.1.0.0 - Updated README.md with new usage and version details - Added CHANGELOG.md (v1.1.0 updates) - Improved error handling when EnableOutputToConsole is missing in Web.config - Prepared project for clean NuGet packaging without dependency warnings
1 parent f474427 commit 60c6e2d

File tree

11 files changed

+95
-63
lines changed

11 files changed

+95
-63
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
## [1.1.0] - 2025-02-XX
4+
### Updated
5+
- Replaced `Json.Encode()` with `HttpUtility.JavaScriptStringEncode()`.
6+
- Removed dependency on System.Web.Helpers.
7+
- Improved safety and simplified deployment.
8+
9+
## [1.0.0]
10+
- Initial release.

DotNetOutputToConsole.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetOutputToConsole", "sr
1313
EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
1515
ProjectSection(SolutionItems) = preProject
16+
CHANGELOG.md = CHANGELOG.md
1617
LICENSE = LICENSE
1718
README.md = README.md
1819
EndProjectSection

src/DotNetOutputToConsole/DotNetOutputToConsole.csproj

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<Deterministic>true</Deterministic>
15+
<!-- NuGet Package Version -->
16+
<Version>1.1.0</Version>
17+
<!-- DLL Assembly Versions -->
18+
<AssemblyVersion>1.1.0.0</AssemblyVersion>
19+
<FileVersion>1.1.0.0</FileVersion>
20+
<InformationalVersion>1.1.0</InformationalVersion>
1521
<!-- NuGet Metadata -->
1622
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
1723
<PackageId>DotNetOutputToConsole</PackageId>
18-
<Version>1.0.0</Version>
1924
<Authors>lived</Authors>
2025
<Company>
2126
</Company>
@@ -33,7 +38,7 @@
3338
<!-- Recommended for NuGet publishing -->
3439
<RepositoryType>git</RepositoryType>
3540
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
36-
<PackageReleaseNotes>Initial release</PackageReleaseNotes>
41+
<PackageReleaseNotes>Version 1.1.0 - Improved no-dependency version using HttpUtility.JavaScriptStringEncode.</PackageReleaseNotes>
3742
</PropertyGroup>
3843
<!-- Debug -->
3944
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -58,37 +63,9 @@
5863
</PropertyGroup>
5964
<!-- References -->
6065
<ItemGroup>
61-
<Reference Include="Microsoft.Web.Infrastructure, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
62-
<HintPath>..\..\packages\Microsoft.Web.Infrastructure.2.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
63-
</Reference>
6466
<Reference Include="System" />
6567
<Reference Include="System.Configuration" />
66-
<Reference Include="System.Configuration.ConfigurationManager">
67-
<HintPath>..\..\packages\System.Configuration.ConfigurationManager.10.0.0\lib\net462\System.Configuration.ConfigurationManager.dll</HintPath>
68-
</Reference>
69-
<Reference Include="System.Core" />
7068
<Reference Include="System.Web" />
71-
<Reference Include="System.Web.Helpers">
72-
<HintPath>..\..\packages\Microsoft.AspNet.WebPages.3.3.0\lib\net45\System.Web.Helpers.dll</HintPath>
73-
</Reference>
74-
<Reference Include="System.Web.Razor">
75-
<HintPath>..\..\packages\Microsoft.AspNet.Razor.3.3.0\lib\net45\System.Web.Razor.dll</HintPath>
76-
</Reference>
77-
<Reference Include="System.Web.WebPages">
78-
<HintPath>..\..\packages\Microsoft.AspNet.WebPages.3.3.0\lib\net45\System.Web.WebPages.dll</HintPath>
79-
</Reference>
80-
<Reference Include="System.Web.WebPages.Deployment">
81-
<HintPath>..\..\packages\Microsoft.AspNet.WebPages.3.3.0\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
82-
</Reference>
83-
<Reference Include="System.Web.WebPages.Razor">
84-
<HintPath>..\..\packages\Microsoft.AspNet.WebPages.3.3.0\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
85-
</Reference>
86-
<Reference Include="System.Xml.Linq" />
87-
<Reference Include="System.Data.DataSetExtensions" />
88-
<Reference Include="Microsoft.CSharp" />
89-
<Reference Include="System.Data" />
90-
<Reference Include="System.Net.Http" />
91-
<Reference Include="System.Xml" />
9269
</ItemGroup>
9370
<!-- Code files -->
9471
<ItemGroup>
@@ -100,6 +77,7 @@
10077
<ItemGroup>
10178
<None Include="packages.config" />
10279
<None Include="LICENSE" Pack="true" PackagePath="" />
80+
<None Include="README.md" />
10381
</ItemGroup>
10482
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
10583
<!-- Import NuGet Build Tasks Pack 6.14.0 (optional if present on build machine) -->

src/DotNetOutputToConsole/DotNetOutputToConsole.nuspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<package>
33
<metadata>
44
<id>DotNetOutputToConsole</id>
5-
<version>1.0.0</version>
6-
<authors>lived</authors>
7-
<owners>lived</owners>
5+
<version>1.1.0</version>
6+
<authors>livedcode</authors>
7+
<owners>livedcode</owners>
88
<license type="expression">MIT</license>
99
<projectUrl>https://github.com/livedcode/DotNetOutputToConsole</projectUrl>
1010
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-

2-
1+
using System.Configuration;
32
using System.Web;
43

54
namespace DotNetOutputToConsole
@@ -8,14 +7,21 @@ public class DotNetOutputToConsoleHttpModule : IHttpModule
87
{
98
public void Init(HttpApplication context)
109
{
10+
context.BeginRequest += (s, ev) =>
11+
{
12+
string enabled = ConfigurationManager.AppSettings["EnableOutputToConsole"] ?? "false";
13+
HttpContext.Current.Application["EnableOutputToConsole"] = enabled;
14+
};
15+
1116
context.Error += (sender, e) =>
1217
{
1318
var ex = HttpContext.Current?.Server.GetLastError();
1419
if (ex != null)
15-
DotNetOutputToConsoleLogger.LogError($"Unhandled Exception: {ex.Message}");
20+
DotNetOutputToConsoleLogger.LogError("Unhandled Exception: " + ex.Message);
1621
};
1722
}
1823

1924
public void Dispose() { }
2025
}
2126
}
27+
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using System.Web;
3-
using System.Configuration;
4-
using System.Web.Helpers;
53

64
namespace DotNetOutputToConsole
75
{
@@ -13,35 +11,36 @@ public static class DotNetOutputToConsoleLogger
1311
{
1412

1513
private static bool IsEnabled =>
16-
string.Equals(ConfigurationManager.AppSettings["EnableOutputToConsole"], "true", StringComparison.OrdinalIgnoreCase);
14+
string.Equals(
15+
HttpContext.Current?.Application["EnableOutputToConsole"]?.ToString(),
16+
"true",
17+
StringComparison.OrdinalIgnoreCase);
1718

18-
public static void LogInfo(string message)
19-
{
20-
if (!IsEnabled) return;
21-
WriteScript("info", message);
22-
}
19+
private static string Escape(string input) =>
20+
HttpUtility.JavaScriptStringEncode(input ?? string.Empty);
2321

24-
public static void LogError(string message)
22+
private static void WriteToResponse(string script)
2523
{
26-
if (!IsEnabled) return;
27-
WriteScript("error", message);
24+
var ctx = HttpContext.Current;
25+
if (ctx == null || !IsEnabled)
26+
return;
27+
28+
ctx.Response.Write($"<script>{script}</script>");
2829
}
2930

31+
public static void LogInfo(string message) =>
32+
WriteToResponse($"console.info(\"{Escape(message)}\");");
33+
3034
public static void LogVariable(string name, object value)
3135
{
32-
if (!IsEnabled) return;
33-
string combined = $"{name}: {value}";
34-
WriteScript("log", combined);
36+
string safeName = Escape(name);
37+
string safeValue = Escape(value?.ToString());
38+
WriteToResponse($"console.log(\"{safeName}: {safeValue}\");");
3539
}
3640

37-
private static void WriteScript(string level, string message)
38-
{
39-
var context = HttpContext.Current;
40-
if (context?.Response == null) return;
41-
42-
var encoded = Json.Encode($"{level.ToUpper()}: {message}");
43-
context.Response.Write($"<script>console.{level}({encoded});</script>");
44-
}
41+
public static void LogError(string message) =>
42+
WriteToResponse($"console.error(\"{Escape(message)}\");");
4543
}
46-
}
44+
}
45+
4746

src/DotNetOutputToConsole/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
A secure ASP.NET Framework (4.8 / 4.8.1) helper library that writes logs, variables, and exceptions directly to the browser console — perfect for UAT and DEV environments.
44

5+
## What's New in v1.0.0
56
## Features
67
- Write messages, variables, and errors to the browser console (`console.info`, `console.log`, `console.error`)
78
- Automatically logs unhandled exceptions globally
@@ -12,6 +13,26 @@ A secure ASP.NET Framework (4.8 / 4.8.1) helper library that writes logs, variab
1213
- Includes unit tests and a demo web app
1314
- Fully compatible with .NET Framework 4.8 to 4.8.1
1415

16+
17+
## What's New in v1.1.0
18+
- Removed dependency on `System.Web.Helpers` (`Json.Encode()` no longer required)
19+
- Now uses **HttpUtility.JavaScriptStringEncode** (safe, built-in, no external packages)
20+
- Improved XSS safety logic
21+
- Cleaned references to reduce DLL size
22+
- Updated module to correctly handle missing AppSettings
23+
- Assembly version sync: `1.1.0.0`
24+
- NuGet package version: `1.1.0`
25+
26+
## Features
27+
- Write messages, variables, and errors to the browser console (`console.info`, `console.log`, `console.error`)
28+
- Automatically logs unhandled exceptions globally
29+
- Works with any ASP.NET Web Forms or MVC project
30+
- Simple global toggle via web.config
31+
- No third-party dependencies
32+
- Includes unit tests and demo web app
33+
- Fully compatible with .NET Framework 4.8 to 4.8.1
34+
35+
1536
## Installation
1637
Install from NuGet using the Package Manager Console:
1738

src/DotNetOutputToConsole/package/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
A secure ASP.NET Framework (4.8 / 4.8.1) helper library that writes logs, variables, and exceptions directly to the browser console — perfect for UAT and DEV environments.
44

5+
## What's New in v1.0.0
56
## Features
67
- Write messages, variables, and errors to the browser console (`console.info`, `console.log`, `console.error`)
78
- Automatically logs unhandled exceptions globally
@@ -12,6 +13,26 @@ A secure ASP.NET Framework (4.8 / 4.8.1) helper library that writes logs, variab
1213
- Includes unit tests and a demo web app
1314
- Fully compatible with .NET Framework 4.8 to 4.8.1
1415

16+
17+
## What's New in v1.1.0
18+
- Removed dependency on `System.Web.Helpers` (`Json.Encode()` no longer required)
19+
- Now uses **HttpUtility.JavaScriptStringEncode** (safe, built-in, no external packages)
20+
- Improved XSS safety logic
21+
- Cleaned references to reduce DLL size
22+
- Updated module to correctly handle missing AppSettings
23+
- Assembly version sync: `1.1.0.0`
24+
- NuGet package version: `1.1.0`
25+
26+
## Features
27+
- Write messages, variables, and errors to the browser console (`console.info`, `console.log`, `console.error`)
28+
- Automatically logs unhandled exceptions globally
29+
- Works with any ASP.NET Web Forms or MVC project
30+
- Simple global toggle via web.config
31+
- No third-party dependencies
32+
- Includes unit tests and demo web app
33+
- Fully compatible with .NET Framework 4.8 to 4.8.1
34+
35+
1536
## Installation
1637
Install from NuGet using the Package Manager Console:
1738

Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)