Why is this built-in Source Code Editor in n-gen.net CMS?

The purpose of this Source Code Editor tool is to provide an n-gen.net CMS Admin with a convenient way to view, edit, create, and delete text-based files directly from the browser.

Site owners may encounter situations where a quick file modification is needed without taking the site offline or using FTP. This tool enables rapid fixes for typos, configuration adjustments, or small code enhancements directly through the admin interface.

What Can You Do With the Source Code Editor?

View and Edit Files

  • Edit any text-based file - ASPX, CS, CSS, JS, HTML, XML, SQL, and more

  • Syntax highlighting - CodeMirror editor with automatic language detection

  • Line numbers - Easy navigation through large files

  • Bracket matching - Visual indication of matching brackets

  • Preview support - Preview HTML, CSS, and JavaScript files in a new window

Search and Navigate

  • Search files - Find files by name across the entire web root

  • Sort columns - Sort by Path, Name, Size, or Modified date

  • Pagination - Browse through large file lists with 50 files per page

  • File icons - Visual indicators for different file types

Create and Delete

  • Create new files - Add new text-based files to the system

  • Delete files - Remove unwanted files with confirmation

  • Auto-backup - Automatic .bak backup before saving changes

File Organization

File List Display

  • Path - The directory path relative to the web root
  • Name - The file name with extension
  • Size - File size in B, KB, MB, or GB
  • Modified - Last modification date and time
  • Actions - Edit (pencil) and Delete (minus) icons

File Sorting

  • Click column headers - Sort by Path, Name, Size, or Modified
  • Toggle direction - Click again to reverse sort order
  • Sort indicator - ▲ (ASC) or ▼ (DESC) shows current sort
  • Persistent sorting - Sort preference is remembered during your session

Search

  • Filename search - Search for files by name (case-insensitive)
  • Clear search - Click ✕ in the search box to clear and show all files
  • Search results - Shows matching files with count

File Operations

Editing Files

  1. Click the pencil icon next to any file
  2. View file information - File name, path, size, modified date, and type
  3. Edit the content - CodeMirror editor with syntax highlighting
  4. Save changes - Click the Save button
  5. Preview (HTML files) - Click Preview to see rendered output
  6. Cancel - Return to file list without saving

Auto-Backup

When you open a file for editing, an automatic backup is created with a .bak extension in the same directory. This backup is updated every time you save the file.

Note: If you don't delete your .bak files manually the files will be deleted automatically when the application pool refreshes. Your web server setup defines these intervals but clean-up typically happens daily.

Creating New Files

  1. Click "New File" - Opens the create file modal
  2. Enter file path - Relative to the web root (e.g., /scripts/myscript.js)
  3. Enter file content - Write the initial content
  4. Click "Create" - The file is created and you return to the file list

Deleting Files

  1. Click the minus icon next to any file
  2. Confirm deletion - A confirmation dialog asks "Are you sure?"
  3. File is deleted - Both the file and its .bak backup are removed

Supported File Types and CodeMirror Modes

File Extension CodeMirror Mode Preview Available
.asax, .ashx, .cs text/x-csharp
.css, .skin text/css
.js text/javascript
.json application/json
.htm, .html, .aspx, .ascx htmlmixed
.sql, .dml, .ddl text/x-sql
.xml, .svg, .xsl, .xslt application/xml ✅ (.svg only)
.config text/xml

Important Notes

  • No code compilation - This tool edits source files directly. Changes take effect immediately.

  • Backup before editing - Always make a backup before making significant changes.

  • System File Updater - For official updates, use the built-in System File Updater tool to avoid overwriting custom modifications.

  • File permissions - The web application must have write permissions to the files and folders you are editing.

  • Encoding - Files are saved with UTF-8 encoding.

  • App_Data folder - Files in App_Data are excluded from the file list to protect sensitive data.

Use Cases

1. Quick Fix

  • Correcting a typo in a configuration file
  • Updating a hardcoded value in a source file

2. Content Updates

  • Modifying HTML content in .aspx files
  • Updating CSS styles
  • Editing JavaScript functionality

3. Configuration Changes

  • Updating application settings
  • Modifying XML configuration files

4. Development

  • Adding new features to custom modules
  • Debugging code issues
  • Creating new template files


Note:
All operations that can be performed with the Source Code Editor can also be performed as FTP download, changes made in a text editor and FTP upload.
However, the Source Code Editor provides an integrated, immediate, and secure way to manage files directly from the admin interface with an automated backup. This way you do not have to use any third party programs or pass on FTP credentials.

Source Code Editor

Overview

The Source Code Editor is a utility for the n-gen.net CMS that provides administrators with direct access to view, edit, create, and delete text-based files in the web application. It uses the CodeMirror editor with syntax highlighting for multiple programming languages and provides a secure, user-friendly interface for file management.

Features

a. File Management

  • Browse files - View all editable files in the web root and sub folders

  • Search files - Find files by name

  • Sort files - Click column headers to sort by Path, Name, Size, or Modified date

  • Pagination - Navigate through large file lists with 64 files per page

  • File icons - Visual indicators for different file types

b. Code Editor

  • Syntax highlighting - Automatic language detection with CodeMirror

  • Line numbers - Easy navigation through files

  • Bracket matching - Visual indication of matching brackets

  • Line wrapping - Long lines wrap for better readability

  • Automatic mode detection - CodeMirror mode is selected based on file extension

c. File Operations

  • Create new files - Add new text-based files with custom content

  • Edit existing files - Modify any text-based file (except protected files)

  • Delete files - Remove unwanted files with confirmation

  • Preview - View HTML, CSS, and JavaScript files in a new window

d. Safety Features

  • Auto-backup - .bak files are created automatically when editing

  • Protected files - web.config and tool source files are blocked

  • Delete confirmation - Confirmation dialog before file deletion

  • Security auditing - All file operations are logged

  • CSRF protection - Prevents cross-site request forgery

e. User Experience

  • Intuitive interface - Clean, modern design aligned with n-gen.net CMS

  • Responsive design - Works on desktop and mobile devices

  • Status messages - Clear success/error/warning indicators

  • File information - View file details before editing


Technical Details

What the Tool Does

  1. Scans the web root for editable text files

  2. Displays files with icons, size, and modification date

  3. Opens selected files in CodeMirror editor with syntax highlighting

  4. Saves changes with automatic .bak backup

  5. Creates new files with user-specified content

  6. Deletes files after confirmation

File Operations

-- Opening a file
Open file → Create .bak backup → Display in CodeMirror
-- Saving a file
Save file → Update .bak backup → Return to file list
-- Creating a file
Validate path → Create directory structure → Write content
-- Deleting a file
Confirm deletion → Delete file → Delete .bak backup

Security Architecture

  • Protected files - Hard-coded exclusion list for sensitive files

  • Path validation - Ensures all paths are within the web root

  • Extension whitelist - Only specified extensions can be edited

  • Security logging - All file operations and blocked attempts are logged

  • Session validation - IP and user-agent verification

  • CSRF protection - Token-based validation for POST requests

Protected Files List

The following files are permanently blocked from any operation:

  • web.config - Database connection strings and sensitive configuration

  • web.debug.config - Debug configuration

  • web.release.config - Release configuration

  • admTextEditor.aspx - The Source Code Editor itself

  • admTextEditor.aspx.cs - The Source Code Editor code-behind

  • admDbEditor.aspx - SQL Inspector tool

  • admDbEditor.aspx.cs - SQL Inspector code-behind

  • global.asax - Application-level configuration

Supported File Types

Category Extensions
Source Code .asax, .ascx, .ashx, .aspx, .cs
Web Files .htm, .html, .css, .js, .xml, .svg
Configuration .config, .ini, .json, .skin
Data Files .sql, .dml, .ddl, .csv, .txt
Scripts .ps1, .bat, .cmd

Note: .log files are excluded from editing to preserve audit trails.

CodeMirror Modes

The tool automatically selects the appropriate CodeMirror mode based on file extension:

  • text/x-csharp - .asax, .ashx, .cs

  • text/css - .css, .skin

  • text/javascript - .js

  • application/json - .json

  • htmlmixed - .htm, .html, .aspx, .ascx

  • text/x-sql - .sql, .dml, .ddl

  • application/xml - .xml, .svg, .xsl, .xslt

Security Considerations

Access Control

  • Level 4 required - Only Site Owners (level 4 users) can access the Source Code Editor

  • CSRF protection - Prevents cross-site request forgery attacks

  • Authentication - Must be logged in with valid credentials

  • Session validation - IP and user-agent verification

  • Timeout - Automatic logout after 30 minutes of inactivity

Data Protection

  • File path validation - Prevents directory traversal attacks

  • Extension whitelist - Only specified file types can be edited

  • Protected files - Hard-coded exclusion list for sensitive files

  • CSRF tokens - Protects against cross-site request forgery

  • Auto-backup - .bak files provide rollback capability

Audit Trail

  • All file operations are logged - Every view, edit, create, and delete action is recorded
  • Security violations are logged - Attempts to access protected files are recorded
  • Log file location - /App_Data/pro_db.log (shared with other admin tools)

File operations are logged to `/App_Data/pro_db.log` with:

  • Timestamp - When the operation occurred

  • User - Who performed the operation

  • IP address - Where the request originated

  • Operation type - OPEN, SAVE, CREATE, DELETE, PREVIEW

  • File path - The file involved

  • Status - Success or failure

Protected File Attempts

Attempts to access protected files (web.config, tool source files, etc.) are logged as security violations:

BLOCKED: Attempt to access web.config by UserName
BLOCKED: Attempt to access protected file /admTextEditor.aspx by UserName

Performance Impact

During File Operations

  • File scanning - The entire web root is scanned for files (cached in session)

  • File reading - Files are read into memory for editing

  • File writing - Files are saved immediately

  • Search - Filename search is case-insensitive

Optimization

  • File list caching - The file list is cached in session after the first scan

  • Pagination - Only 50 files are displayed at a time

  • Selective scanning - Only editable file types are included

  • Excluded folders - App_Code, bin, and App_Data are excluded

What the Tool Does Not Do

  1. Edit binary files or images - Only text-based files are supported

  2. Access web.config - Protected for security reasons

  3. Modify tool source files - Tool source files are protected

  4. Edit log files - .log files are excluded to preserve audit trails

  5. Access App_Data - App_Data folder is excluded from the file list

  6. Compile code - Source code changes take effect immediately

Troubleshooting

Error: "Access denied. This file cannot be edited."

  • Cause: The file is protected or has a non-editable extension

  • Solution: Protected files cannot be edited for security reasons

Error: "File not found"

  • Cause: The file may have been moved or deleted

  • Solution: Refresh the file list and try again

Error: "File already exists" (when creating)

  • Cause: A file with the same path already exists

  • Solution: Choose a different filename or delete the existing file first

Preview not working

  • Cause: The file type may not support preview or the preview folder doesn't exist

  • Solution: Only HTML, CSS, JS, and XML files can be previewed. Ensure the /preview/ folder exists.

Syntax highlighting not working

  • Cause: The file extension may not be recognized

  • Solution: The tool uses file extensions to determine the CodeMirror mode. Ensure your file has a recognized extension.

File list is empty

  • Cause: No editable files found or files are in excluded folders

  • Solution: Check that you have text-based files in the web root and they have recognized extensions

Best Practices

  1. Always backup before editing - The tool creates .bak files automatically, but additional backups are recommended

  2. Test changes in development first - If possible, test changes in a development environment before applying to production

  3. Review changes before saving - Use the CodeMirror editor to review your changes carefully

  4. Use the preview feature - For HTML, CSS, and JavaScript files, use Preview to verify your changes

  5. Keep track of modifications - Document your changes for future reference

  6. Use version control - For significant changes, use a version control system like Git

  7. Monitor log files - Regularly review /App_Data/pro_db.log for security events

  8. Never edit web.config - Protected for security reasons

Last updated 29-06-2026 14:46:14