Skip to main content

.NET Core Environment Tags (and how they can bite!)

My brief story which lead me to look to an unlikely culprit of what was causing a bug in my .NET Core application.

The background

This is a 3-tier application (front-end, business logic and data access layers) built in .NET Core. The application itself is actually a .NET Framework application that I am converting to .NET Core. I am converting this application not only for future support, but for performance improvements.

If you haven't been on the bandwagon, .NET Framework isn't moving past version 4.8. As mentioned in the Microsoft blog, .NET Core will continue to get new features at a faster rate, and will be the preferred framework to build new apps moving forward.

The application is a simple in that it has a data provider service supported by dependency injection, which uses a SQL connection to call a stored procedure to return data back into a model, which gets loaded into a view that contains a grid (ie. <table>) on the webpage. Data is loaded based on the user that is logged into the application - different users will see different data in the grid. Identity server is managing the user logins.

Easy, right? Local testing looks good, everything is returning what it should. The SQL connection is returning data from the stored procedure. I am seeing the data being properly passed into the grid.

Let's deploy this to QA.

QA doesn't work

Nothing is showing up in the grid on the webpage. Hm, that is odd. Okay - what could be the problem here? I first check to see if the values are being passed correctly into the stored procedure, as that is the first place I tend to look. My reasoning behind this is maybe the user information that the stored procedure needs is somehow not getting set properly.

I add some logging like seen here within my controller and redeploy to QA. In my logging I see that the stored procedure is getting values from the user's identity, so that doesn't seem to be the problem.

I next compare the stored procedure between my local copy and on QA, as it is possible that the procedure is different between environments and it was a fluke that my local environment returned proper data. Luckily, VS Code allows us to quickly and easily compare files.

I open up a new tab with ctrl/cmd + n and paste in the stored procedure in question. I saved the file and repeated the process with the stored procedure in the other environment. Holding ctrl/cmd + shift + p I typed "compare" and chose Files: Compare Active File With... and chose the other file.

Compare active file dialog
Compare active file dialog

The files are the same.

Running out of ideas

I go back to my QA url since my application is a web app and bring up the console by clicking f12 (in Chrome, or you can right-click and choose Inspect Element) and see if there are any errors. I do not see any errors.

What about the Content Security Policy - could that be causing any errors? The CSP's purpose is to prevent XSS (Cross-site scripting) and if you don't have the CSP configured properly, you can prevent CSS or JS from loading on your site. Could the CSP be preventing the grid from loading data on our QA server (barring everything else is set up correctly)? Unlikely. CSP errors are shown in the console, and we would have seen the CSP error locally if it were to be happening.

Stuck

After exhausting all of my obvious options, what else could be causing this bug? Let's take a deeper look into the view and at our environment tag helpers we have in _Layout.cshtml. We have code that is similar to this:

Environment tag helpers
Our code in _Layout.cshtml

My code looks normal enough, we are loading css in non-bundled files in the Development environment and in non-Development environments we are loading one bundled file. Besides being a recommended best-practice to bundle resource files on web pages, I don't see anything wrong. 

I happen to double-check the bundleconfig.json and immediately see the problem. I did not configure the bundling correctly:

Incomplete bundleconfig.json
This is wrong!

I modify this bundleconfig.json file to include the other files I need:

A properly-configured bundleconfig.json
This is correct!

and lo-and-behold, after deploying to QA I see data on the webpage! It turns out that because my css was missing, I wasn't seeing any data on my webpage! What I learned, and I hope you do too, is that you should consider checking your bundleconfig.json and any <environment> tags when diagnosing problems in .NET Core web apps.

Comments

  1. I was diagnosed as HEPATITIS B carrier in 2013 with fibrosis of the
    liver already present. I started on antiviral medications which
    reduced the viral load initially. After a couple of years the virus
    became resistant. I started on HEPATITIS B Herbal treatment from
    ULTIMATE LIFE CLINIC (www.ultimatelifeclinic.com) in March, 2020. Their
    treatment totally reversed the virus. I did another blood test after
    the 6 months long treatment and tested negative to the virus. Amazing
    treatment! This treatment is a breakthrough for all HBV carriers.

    ReplyDelete

Post a Comment

Popular posts from this blog

UI redesigns are mostly a waste of time

To preface the article, I primarily work on, and prefer, back-end code. I've been involved in both web and software development for over 4 years now and worked with many front-end and back-end frameworks. New Twitter UI Before all of the UI designers that read this go out and riot and champion against me for saying UI redesigns are a waste of time, let me say that I do value design . I think at the bare minimum, a product or website needs to be usable , and if you possess a good eye and steady hand , you should feel compelled to create something that looks pleasing. David Just stop redesigning the UI all the time . UI redesigns, in my opinion, are a waste of time 95% of the time. Let me explain further. No one cares Come see our fresh new look ! What about our new  material design , come see! I'm sorry, but besides fixing the UI where it impacts the usability of your application, no one is raving about how a redesign makes the application any better.

[Fix] - ASUS PCE-AC68 adapter (no internet)

There seem to be a lot of problems with this adapter, even with such strong performance . Why so many issues? I'm not quite sure, but I needed to find a fix because I kept on losing wifi. The ASUS PCE-AC68 The fix Keeping it short - this is how I fixed the issue: Downloaded the driver for my OS from ASUS's support page -  https://www.asus.com/us/Networking/PCEAC68/HelpDesk_Download/ (in my case it was Windows 10 64-bit). Open Device Manager by holding the Windows key and pressing R, then typing "devmgmt.msc" and hitting Enter. (Don't worry, this isn't a scam . We are simply opening Window's Device Manager through the Microsoft Management Console snap-in .) Navigate to the yellow warning sign sitting under Network adapters and right click it. Select Update driver . Select Browse my computer for driver software  and choose the following path of the OS that you have installed on your computer. (The path for the driver on my computer was C

Logging into a website with Powershell

Powershell is great, and it's lately been my go-to shell while I'm working on Windows. Sorry command prompt I really don't do a lot of work in the shell, but I do like to play with low-level interfaces from time to time. The article is about Linux shells, but goes into good explanation about what a shell is if you don't know. Log into a website Today, I wanted to do something that I have never really tried before and that is logging into a website using Powershell . The concepts behind this are quite simple really, as Powershell has support to send HTTP requests  and that's usually all we need, unless the server has CSRF protections in place (which it should). We are going to attempt  to log in to my favorite website for buying socks, Absolute Socks : Is that a turkey?! In order to do that, we need to have a login. So if you don't already have an account on www.absolutesocks.com , go make one now. Viewing the login request On websites,