Deploying My .NET Blog to Render

Deploying My .NET Blog to Render

Recently, I set out to publish my personal .NET blog using Render, a platform I had not used before but it looked perfect for simple hosting. It did not go smoothly. Here is what went wrong, what I learned, and how I got it working.

My Goal

I had built a simple ASP.NET Core MVC blog project with a controller that serves posts from HTML files. I just wanted it hosted somewhere quick, and Render seemed like a good option. It was... after some trial and error.

Attempt 1: Native .NET - Static Site

Initially, I followed Render's static site guide. The default build command I used looked like this:

dotnet publish MyBlog/MyBlog.csproj -c Release -o out

But this failed with:

bash: line 1: dotnet: command not found

Render says their Static Site option is "great for blogs" and that sounded right at first. But it is only for pure static HTML/CSS/JS with no backend code. That was the problem.

Attempt 2: Docker Deployment - Dynamic Site

A Web Service supports server-side code and building from a Dockerfile, so it was a better fit for my C# ASP.NET Core app.

I wrote a Dockerfile that used the official .NET 8 SDK image, published the app, and exposed port 80.

I also added a render.yaml file to tell Render how to build and deploy the app using Docker. Once this was in place, Render built and ran the app. But...

A Mysterious "Not Found"

Even though the app deployed, when I visited the URL I got a "Not Found" page. It was not a 404 from my app, it was Render's own page.

After digging in, I realized I had left in some non-standard code from a .NET 9 preview template I had previously experimented with. Once I removed it and went back to the basic middleware setup (UseStaticFiles(), MapControllerRoute(), etc.), everything worked.

Success!

After cleaning up the Dockerfile and reverting my Program.cs to the basic setup, the site deployed correctly. I finally saw something other than "Not Found".


TL;DR: If you're deploying a .NET app to Render, use a Web Service (not a Static Site), build with Docker, stick with .NET 8, and keep the middleware simple unless you're sure you need fancy stuff.

Comments

No comments yet.

Add a comment