A .NET 8 ASP.NET Core web application that demonstrates loading and rendering HTML content from various sources.
- String-based HTML rendering: Load HTML content from string variables
- File-based HTML rendering: Load HTML content from files
- File upload support: Upload and render HTML files through a web interface
- Sample HTML files: Pre-built examples demonstrating different capabilities
- Interactive control panel: Web-based interface for testing different rendering methods
- CORS enabled: Allows cross-origin requests
- Real-time rendering: Immediate display of HTML content in the browser
- .NET 8 SDK (for local development)
- Docker (for containerized deployment)
- Clone or download the project
- Navigate to the project directory
- Build the application:
dotnet build
- Run the application:
dotnet run
- Open your browser and navigate to
http://localhost:54568
- Ensure Docker is installed and running
- Use the provided build script:
chmod +x docker-run.sh ./docker-run.sh
- Access the application at
http://localhost:8080
For detailed Docker instructions, see DOCKER.md.
/
- Displays sample HTML content loaded from a string/control
- Interactive control panel for testing different rendering methods
POST /render
- Render HTML from string or file{ "source": "string|file", "content": "HTML content (for string source)", "filePath": "path/to/file.html (for file source)" }
POST /upload
- Upload and render HTML fileGET /samples
- Get list of available sample filesGET /samples/{fileName}
- Render a specific sample file
The application includes three sample HTML files in the samples/
directory:
simple.html
- Basic HTML with modern CSS stylinginteractive.html
- Interactive elements with JavaScript functionalitydashboard.html
- Complex dashboard with real-time updates and animations
Visit http://localhost:54568
to see HTML content loaded from a string variable.
Visit http://localhost:54568/control
to:
- Enter custom HTML content and render it
- Upload HTML files for rendering
- Browse and load sample files
# Render HTML from string
curl -X POST http://localhost:54568/render \
-H "Content-Type: application/json" \
-d '{"source": "string", "content": "<h1>Hello World!</h1>"}'
# Render HTML from file
curl -X POST http://localhost:54568/render \
-H "Content-Type: application/json" \
-d '{"source": "file", "filePath": "/path/to/your/file.html"}'
- Minimal API: Uses .NET 8's minimal API approach for clean, concise code
- Content-Type handling: Properly sets
text/html
content type for browser rendering - Error handling: Comprehensive error handling for file operations and invalid requests
- Security: File upload validation to ensure only HTML files are processed
- Performance: Async/await pattern for file I/O operations
The application demonstrates several important concepts:
- String-based HTML rendering: Shows how to serve HTML content stored as strings
- File-based rendering: Demonstrates reading HTML files and serving their content
- Dynamic content: Includes server-side data (like current timestamp) in rendered HTML
- Interactive features: JavaScript functionality works seamlessly in rendered content
- RESTful API design: Clean API endpoints for different rendering scenarios
You can easily extend this application by:
- Adding more sample HTML files to the
samples/
directory - Implementing HTML template engines (Razor, Handlebars, etc.)
- Adding authentication and authorization
- Implementing HTML content validation and sanitization
- Adding database storage for HTML templates
- Creating a rich text editor for HTML content creation
- The application listens on
http://0.0.0.0:54568
to allow external access - CORS is enabled for cross-origin requests
- Static file serving is configured (though no static files are currently used)
- The application uses the development environment by default
This application serves as a solid foundation for any system that needs to dynamically load and render HTML content in a .NET environment.