A simple blog application built with ASP.NET Core 9 and Razor Pages that allows users to view and create blog posts.
- View Blog Posts: Display a list of all blog posts with titles, content previews, and creation dates
- Create New Posts: Add new blog posts through a user-friendly form
- In-Memory Storage: Posts are stored in memory using a List (no database required)
- Modern UI: Clean, responsive design using Bootstrap 5 and Bootstrap Icons
- Hot Reload: Real-time development with automatic reloading on code changes
- .NET 8 or 9 SDK
- Visual Studio Code with C# extension
- Git (optional)
Download and install the .NET 8 or 9 SDK from Microsoft's official website.
Install the following VS Code extensions for the best development experience:
- C# (ms-dotnettools.csharp)
- .NET Runtime Install Tool (ms-dotnettools.vscode-dotnet-runtime)
- Open the project in VS Code
- Press
F5to start debugging, or - Use
Ctrl+Shift+Pand run "Tasks: Run Task" → "watch" for hot reload
# Navigate to the project directory
cd BlogApp
# Run the application
dotnet run
# Or run with hot reload
dotnet watch runOpen your browser and navigate to:
- Home Page:
https://localhost:(Port)orhttp://localhost:(Port) - Blog Posts:
https://localhost:(Port)/Blog - Create Post:
https://localhost:(Port)/CreatePost
BlogApp/
├── Models/
│ └── BlogPost.cs # Blog post model
├── Services/
│ └── BlogService.cs # In-memory blog post service
├── Pages/
│ ├── Index.cshtml # Home page
│ ├── Blog.cshtml # Blog posts list page
│ ├── CreatePost.cshtml # Create new post page
│ └── Shared/
│ └── _Layout.cshtml # Main layout template
├── .vscode/
│ ├── launch.json # VS Code debug configuration
│ ├── tasks.json # VS Code build tasks
│ └── extensions.json # Recommended extensions
└── README.md # This file
public class BlogPost
{
public string Title { get; set; }
public string Content { get; set; }
public DateTime CreatedAt { get; set; }
}Posts are stored in a List<BlogPost> within the BlogService class. The service includes:
- Sample posts for demonstration
- Methods to get all posts (ordered by creation date)
- Method to add new posts
- Welcome message with links to blog features
- Quick access cards for viewing and creating posts
- Displays all blog posts in a card layout
- Shows post title, content preview, and creation date
- "Create New Post" button for easy navigation
- Responsive design that works on all devices
- Form to create new blog posts
- Client-side and server-side validation
- Automatic redirect to blog list after successful creation
- Clean, user-friendly interface
The application supports hot reload for real-time development:
dotnet watch runVS Code is configured for debugging with:
- Launch configuration for starting the application
- Build tasks for compilation
- Breakpoint support and variable inspection
The create post form includes:
- Required field validation
- Client-side validation using ASP.NET Core's built-in validation
- Server-side validation for security
- Create new Razor Pages in the
Pages/directory - Add corresponding page models (
.cshtml.csfiles) - Update navigation in
_Layout.cshtmlif needed
The application uses Bootstrap 5 for styling. You can customize the appearance by:
- Modifying the CSS in
wwwroot/css/site.css - Updating Bootstrap classes in the Razor pages
- Adding custom CSS classes
To switch from in-memory storage to a database:
- Add Entity Framework Core packages
- Create a DbContext
- Replace the
BlogServicewith database operations - Update the dependency injection in
Program.cs
- Port already in use: Change the port in
Properties/launchSettings.json - Build errors: Run
dotnet restoreto restore packages - Hot reload not working: Ensure you're using
dotnet watch run
- Check the ASP.NET Core documentation
- Review the Razor Pages tutorial
This project is open source and available under the MIT License.