During my last interview it was mentioned that they were considering rewriting their php web apps using ASP.Net. It has been some time since I developed using ASP.Net so I decided to refresh my memory as well as see what has changed. Creating a basic CRUD web app styled with a modern front-end framework is a good place to start. Some other things I will eventually look at are source control, deployment and components. I used bootstrap but I prefer UIKit. Below are my steps and my experience.
Download and install Visual Studio Community
Download and install SQL Server Express
Install/turn on IIS (on my Windows Home)
Windows Run > AppWiz.cpl > Turn windows features on and off
The first thing I did was to use the template. I see improvements. An option to have authentication out-of-the-box as soon as you create your web app. By default the web app uses LocalDB and login and related pages just work. You can read more about LocalDB here – https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-2016-express-localdb
I tried to create content pages manually and got the following error message
This page contains markup that is not valid when attached to a master page
All I really needed to do was right-click master page and select add content page. Another error I encountered was
This version of entity data source wizard is only compatible with entity framework 5
I read a couple posts related to this and they pointed to making sure you have the latest package installs of
This did not help me and eventually I would define it manually e.g.
When changes are made to the database schema remember to right-click and update model from database. ASP.NET Core is useful because .NET Core is designed for cross-platform development/deployment (Windows/Linux/MAC). Another error I encountered was
More than one DbContext was found. Specify which one to use.
Fix – Add-Migration Initial -Context WebApplication1Context and Update-Database. These database commands are similar to migrations in Ruby on Rails. Something new that I encountered was Razor pages. A nice breakdown of what this is about here ASP.NET Core Razor Pages – Introduction. Razor is a simple markup syntax for embedding server code. It integrates with your controllers and views. I am noticing no drag and drop components and no visual models as compared when I used the template with .NET Framework. One of things I wanted to do was create a dropdown for an enum in my model. I was able to accomplish this with a helper as follows
Make sure to include reference to the namespace in which the enum is defined in e.g. @using CustomerFeedback.Models.WebApplication1.Models. After a while I decided I wanted to use the latest bootstrap 4 and not the version bundled with the template (By default the project is created with bootstrap 3.3.7). I tried a couple of things with Nuget and Bower and eventually decided I could start from scratch (without a template) and use Webpack to publish the required include. Doing this made me see the beauty of this. With a blank project I control what gets added and it gave me a better understanding of how things worked. Once I figured out how things worked, I started a new project from scratch to see if I could reproduce what I learnt. These links helped me get started.
Some problems I encountered
Error: EPERM: operation not permitted, rename
Fix – npm cache clean
The CLI moved into a separate package: webpack-cli.
Please install ‘webpack-cli’ in addition to webpack itself to use the CLI.
Fix – npm install webpack-cli -D
Module not found: Error: Can’t resolve ‘popper.js’
Fix – npm install popper.js -save
Finally I ended up with the page you see in the header. Now my stack looks like this. Visual Studio/ASPdotNET Core/MVC/Razor Pages/jQuery/Bootstrap 4/SQL Server/IIS/Webpack/Node. Next blog post I will go through my experience after adding CRUD and authentication. Please share your thoughts and experiences with me in the comments below.