WordPress and .NET (WP.NET)

By Priyanka K on October 22, 2020

WP.NET is WordPress compiled to .NET Core using PeachPie compiler. This means that the original source code of WordPress, which was written in PHP, has been migrated to the .NET platform, which provides the following benefits:
• Improved performance
• Enhanced security
• Extensibility in C# and other .NET languages
• Extensibility using Razor partial views
• Ease of configuration
• Running natively on Azure
With WP.NET, you get all the amazingness of WordPress, but with the robustness, security and performance of .NET. There are, however, a few key differences compared to regular WordPress:
Sourceless distribution: you don’t need any PHP sources on your server with WP.NET
No server-side PHP changes: because WP.NET is compiled PHP code, we do not allow for unsafe practices, such as making changes to the code on the server. If you want to modify the sources, you’ll have to re-compile and re-deploy the project. You’ll thank us later.
Plugins and themes: due to the previous point, plugins and themes also need to be compiled; therefore, you won’t be able to upload a new theme or download and install plugins like you’re used to from WordPress.

Integrate WordPress as ASP.NET Core Middleware

Prerequisites
You will need to have these on your machine before you get started.
1. Visual Studio 2019 IDE / Visual Studio Code
2. The Latest .NET SDK – Get it here
3. MySQL Server Installed and configured, as WordPress will be using this Server Instance for Persistence.

Step 1 – Setting up the MySQL Database

Make sure that the latest versions of both MySQL Server (Community) and MySQL WorkBench installed. If not, download and install them. With that done, Open up MySQL Workbench. Create a blank database/schema for our WordPress Application to run. The tables will be auto-generated by WordPress as soon as the application launches for the first time.

Step 2 – Setting up ASP.NET Core Project

Open up Visual Studio IDE and create a new ASP.NET Core Web Application. This will act as the Container over which WordPress will be running. Make sure that you have selected ASP.NET Core 3.1+.

Step 3 – Installing the Required Package

Install the specified Package from Nuget. Open up your Package Manager Console and run the following snippet.

       Install-Package PeachPied.WordPress.AspNetCore -Version 5.5.1-preview1

Step 4 – Configuring WordPress

Add the connection details to appsettings.json.
“WordPress”: {
“dbhost”: “localhost”
“dbpassword”: “root”,
“dbuser”: “root”,
“dbname”: “wordpressdb”
}
Then open up Startup.cs/ConfigureServices method and add in the following.

 services.AddWordPress(options =>{});

Next, in the Configure method, add the following.
app.UseWordPress();
Then, build and run the application. We will get the default WordPress Installation Wizard.Then like every wordpress website we need to do the initial settings and start working.

References:

https://www.codewithmukesh.com/blog/running-wordpress-on-aspnet-core/
https://www.wpdotnet.com/

Leave a Reply

Contact us!
SCROLL TO TOP