ASP.NET Programing   April 2021


Adventures in ASP.NET Programing

And for the final Pandemic project, I give you the Book Review Page.
ASP.NET driven by a SQL Datbase.
 
Book Reviews in ASP


Update 7/15/2022: I was going to update this progject and add some features, but it seems Microsoft is trying to kill off .NET Framework and move everyont to .NET CORE, so my project doesn't work in Visual Studio Community 2021. I have no idea what this would entail, but it really doesn't make me want to start this all over again.




In Short

The Book review section of my web page is one of my first sections started back in 2003. I've been meaning to give it a face lift for a long time, but with about 200 books, I knew it would be a job. But heck, it's a pandemic, and just how long could it take?

It took about 100 hours.

And yes, I know it's pretty basic, but wow was the learning curve steep. Between learning all the things I needed to learn and to doing all the things I needed to do, this was a nightmare. After it was all done, It's about 4 hours of coding, 2 hours of setup, and 94 hours of learning. The project almost broke me, but it's finally complete and working.


So what did I need to learn?

  • SQL 2016 setup
  • Visual Studio Community Edition 2019
  • ASP.NET, C#, with Forms
  • Frameworks
  • Compliers
  • Object Oriented Code



The Long Version

"Hey, I do most of this for a living. How hard can it be to do absolutely everything?"
Answer: More difficult than expected.


So What was involved?

  • 1 Web Server
    • Learn about issues with upgrading .Net Frameworks
  • 1 SQL Server
    • Learn about new default "features" in SQL 2016
  • Visual Studio Community Edition 2019
    • Learn about Templates, New programing languages, Software Design Methodologies, Object oriented Programing, the difference between Visual Basic and C#, Bugs in Visual Studio, and Unhelpful Error Messages.

How about a few more details?

  • Install a Web Server, SQL Server, and configure Networking between them.
    • Ok, this really is my actual job, so not many unknowns here. But, do not take "unknowns" for fast. With three systems, there are always problems and bug hunts. Particularly when each of these systems have multiple versions. It's just that in this case I expect these bug hunts and have ideas on how to troubleshoot because I've been doing it a long time. Every time a system goes from 2012 to 2016 version or similar there are issues. Every time. This is what makes my job, my job. Somebody has to track down the issues, and find out how to fix them and that person is me.
  • Install SQL Sever
    • Again. New versions always have some "gotchas", and this one was no exception. But at least I'm familiar with what things to check. It still takes time, and it's still very frustrating. (See "And WHY does SQL 2016 turn off external access by default? ARGGGH!!!")
  • Visual Studio
    • New territory. It's been 20+ years since I've programmed. But hey, I read a book about C and C++ 30 years ago so this should be a piece of cake right?
    • At various times in my life I've programmed in Basic, Pascal, TRS 80 Assembly, C, C++, Fortran, Visual Basic, Visual C, Javascript, and ASP. So I thought I was pretty darn good for a non-professional. But given that it's been 20 years, things are a bit fuzzy. Add to that the complication that I have to program in C# when all of the examples are in Visual Basic, and you have a learning curve like a brick wall.
    • Object Oriented programing is not that different right? (I'll just leave this one as "no comment".)
    • The Template based Software Design of Visual Studio. (Tim Screams). Visual Studio 2019 Community Edition is "Template Based". The idea is that the software will setup things for you automatically based on the Template you choose when you first create the project. You have about 50 options for Templates when you start. Your choice here is EXTERMELY IMPORTANT. So before you have written a single line of code or have any idea what you are doing, you have to choose the EXACT correct template, or you will have issues. Lots of Issues. So many issues.
  • Putting it all Together
    • At this point you have installed Visual Studio Community Edition 2019 on your desktop and you have developed a web page that works. Great! Now you need to figure out how to get it working in Production. Translation: "When you installed Visual Studio on your desktop it did LOTS and LOTS of things in the background that you have no idea about and never it mentioned. Now you need to figure out every single one of those things for you to actually get it to work in the real world. If you miss a single little checkbox, you will chase bugs for hours".



I'm a Glutton for punishment

Ok, Unless you're a programmer, much of this will be Greek. This section is so that I have a reference for the next time I have a similar crazy idea. And I seem to know a bunch of programmers that might find it amusing.

------------------------------------------------------------------------
Project Start and "Requirements"

What do I need to complete this project? Can I do it easier? After some false starts I figured on a format and got to work, but even with the smaller review format it was taking forever. Doing this manually was just not going to give me the result I wanted for all the work put in. After checking to see if there was an easy way to do this with some kind of Javascript and a flat file, I figured out that the only way to do this was with programming and a database.

So I figured it was time to brush up on my coding.

I had done what I though was a similar project years ago back in 2000 so I figured this would only take about 8 hours. BAHAHAHAH. That project was in ASP not ASP.NET. It was not object oriented. It did not have framework issues. It did not have a "design philosophy". Begin the descent into madness.

So what do I need?

  • A Web Server
  • A SQL Server
  • Learn how to code in C# with ASP.NET and forms
  • An External File share to store the data
  • Configure the Networking between all of them

Ok, just a few items. At one time or another over the last 30 years I've done a version of all of these. Now I just have to do all of them at the same time and get them all to play nice with each other. This should be no problem, I'll just take a quick lunch a couple days. Right?

------------------------------------------------------------------------
Web Server:

This should be the easy one since I already have one. But, it's running Server 2012 and that only has ASP.NET 4.0 by default. So I need to figure out how to upgrade it to ASP.NET 4.8. Cue Spending 8 hours because "of course" you can't do this without other patches, some registry hacks, and some irritating IIS caching issues. And of course don't get me started with having to run the Application pool with different permissions so that it could access the external File share. Or how Visual Studio complied the project with debug on so that now the service needed write permission and not just read permission because,,, well just because.

------------------------------------------------------------------------
SQL Server:

I do this for work, just what could go wrong? In retrospect I should have remembered that I only setup the servers, then I hand them over to the database people to actually install "SQL Services". So the last time I actually installed SQL from the ground up was SQL Server 2000. What I installed was SQL 2016, and for "security" reasons it turns OFF "allow access from remote computers" by default. Argggh! How would I even know this was a feature that exists! - Waste more hours.

------------------------------------------------------------------------
Visual Studio:

At first I thought this was a total win but I got suckered. Microsoft released a "basic" version of Visual Studio as a free community project and it is rather incredible in what you get. (Even with all the crap I'm going to say about it, it really is incredible in what it offers for free, but wow would it help to have some expert advice). It also has a couple of bugs and omissions that will make it hell to learn while using. So, if you go that route there are a few things you will want to know.

Templates:

First, Microsoft REALLY wants you to learn the newest way to code and will hide everything else from you. Currently what they want you to learn is "CORE" with "RAZOR" in "F#". If you are already a programmer that probably makes sense to you. If you are not, and if you are trying to learn, that is Greek. Unfortunately the Visual Studio Community edition 2019 is "Template" driven. This means that you have to know EXACLTY what all of that means before you can even start. What template you choose will very much determine your experience, and there is no way to know what to choose until you know an incredible amount about everything. So, burn hours and hours here, just to figure out what the hell this means.

After lots of research, in the end I thought of it as

  1. Choose a programing language
  2. Choose a framework/complier
  3. Chose a Design Method

What this comes down to in the real world is choosing your "starting template" from about 40-50 options. Choose from your Chinese menu, 1 Programing Language, 1 Framework, and 1 Software Design Methodology. (Don't mess up a single part or you will waste hours and hours. No pressure)

  1. Programing Languages: Visual Basic, C#, F#
  2. Frameworks/Compilers : ASP, ASP.NET, Bootstrap, CORE, Razor, React Native
  3. Software Design Methodologies: WebForms, MVC

Remember this will be EXTERMELY important on all future things you do. What is most important to this story is that not all of these template options are available with a standard install. Because, well because Microsoft really wants you to program the newest and cool things. So, in order to have the template I would eventually use, you will have to install "additional features". Kinda difficult to do, when you have no idea what you are doing.

I wanted to write this in "ASP.NET, with Forms and C#" because the structure of a single code behind page made sense to me, and because that's what my work used until recently so I have a bunch of code examples to learn from. After creating dozens of new projects base on various templates I finally found the one I was looking for (or so I thought).

  • ASP.NET Web Application (.NET framework) "...You can create ASP.NET Web forms....."
  • .NET Framework 4.8
  • Web Forms

Lots of choices, let choose something

From all of the options how about this one?



This looks good right?
For the love of God, NO!

What you REALLY want is this



Why? (Or, what you want to know before you know what you want to know)

This template adds so much junk that you will never use, so that everything is more complicated than it needs to be. This template also adds subtle configurations that are hidden from the user unless you are very advance. Also this template has bugs. For example during the Publish process it does not include all of the required files and simple does not work. All of this is "ok" by Microsoft because "This is older and unsupported code. We recommend you use our most recent".

------------------------------------------------------------------------
Start Learning C#

Ok, with all that out of the way, how about we start learning how to program in C#?

  • If you are learning to program in 2021, you will look for sample code on the internet.
  • ASP.NET was originally designed in Visual Basic, but somewhere along the line, Microsoft moved to C#.
  • So 50% of the code examples use Visual Basic and 50% use C#. This make it a nightmare to learn.
------------------------------------------------------------------------
Putting it all together

An here is where you start the constant debug loops. You get an error on the server that cannot be resolved, so you simplify the code to help troubleshoot and get a different error. Rinse and repeat. In retrospect, this is where I should have started from day 1 with a simple "Hello World" page. There is a reason that is always first. Ignore at your own peril