When a variable is marked as
const, its value cannot change.
const int BoilingTempCelcius = 100;
A constant must be determinable at compile time, which means only the primitive types (
stringetc) can be marked as const.
However, C# lets you declare a non-primitive type as
const, if you set the value to null:
const SomeComplexType x = null;
Let’s have a look at some strange things that can happen with
const when referencing them from a class library.
Create a new .NET Framework console app project called SomeConsoleApp, and add a class library to the…
Here are some questions I came up with while learning HSTS, and the corresponding answers.
The Strict-Transport-Security header looks like this:
How many source “iterations” would happen when the below code executes?
Most people think one of two things:
Let’s find out the correct answer.
We first need to agree on the definition of an iteration.
Most people think of an iteration as one loop through a foreach/for/while etc.
But what happens when you loop through a foreach?
Behind the scenes, the iterator pattern is implemented.
foreach loop is syntactic sugar for:
In this article I’ll talk about what values an antiforgery token can take on in .NET 5.0.
You should already have a basic understanding of antiforgery tokens and how to use them in .NET 5.0.
If you’ve read my first article on antiforgery tokens, you’ll know that out of the 155 characters that make up the token, the first 5 characters are always the same:
This is because these hard-coded eight bytes are always written to the start of the array before being base64 encoded:
The next 21 characters will always be the same for your application depending…
Here are some questions I came up with while learning about antiforgery tokens and how they can protect against CSRF attacks.
You should already know what a CSRF attack is, and what antiforgery tokens are.
Read my article if you’re interested in how antiforgery tokens work behind the scenes.
A login CSRF attack is the opposite of a normal CSRF attack.
The victim loads a fake website which appears real, and uses it to log in to a website like PayPal, but without the victim knowing, the attacker’s credentials are used behind the scenes.
Once the victim logs in, the…
In this article I’ll talk about how antiforgery tokens work behind the scenes by answering these questions:
You should already know what antiforgery tokens are, and how to use them in Asp.Net Core.
You can skip this section, however it’s much more interesting to follow along by debugging this yourself.
I won’t show all the code here, however it’s a very simple MVC application which has a form and a button to POST the form.
I was curious as to what the best body type is in terms of height, weight, BMI and age.
I’ve recorded all the stats for the ninjas whose runs and stats were shown on TV, for season three and four.
This is something that took me a long time to get working, and there is not much help out there on the internet.
So I’m writing this article to give you the help I wish I had when I was trying to work this out.
Maybe you’re just curious as to how things work behind the scenes, or maybe you’ve found a bug, or need some code you don’t have access to. Whatever your reason is, this article will help you skip all the issues I had.
There are many ways to debug the source code. …
In this article, I’ll show you a scenario where using Reflection can help improve the readability, maintainability, extensibility, and the DRYness of your code.
You’ve written a web app for a car dealership which prints reports about the cars in stock, and what cars have been sold.
Here is what the code looks like at the moment. It’s a simple ASP.NET Core MVC application with one Controller called Home, and two classes for generating the reports.
CarInfo class generates a report for the cars in stock:
CarSales class generates a report for the cars that have…
I’m a software developer who is passionate about learning how things work behind the scenes.