Follow @endyourif rss Facebook LinkedIn

Random number generator only generating one random number

Published on Mar 3, 2020

To generate a random number it involves instantiating the Random class then calling the Next function with a minimum and maximum value as follows: new Random().Next(min, max) so why is it always returning the same number? This commonly occurs when this is being called in a loop.

Understanding IndexOutOfRangeException and ArgumentOutOfRangeException

Published on Mar 2, 2020

You've received the following error: Index was outside the bounds of the array with an IndexOutOfRangeException or you received: An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code Additional information: Index was out of range. Must be non-negative and less than the size of the collection with an ArgumentOutOfRangeException. So what gives? Here is what you need to know.

Solution to SameSite None iFrames with C#

Published on Jan 27, 2020

There has been a lot of kerfuffle over Chrome's upcoming change to how cookies are based when one website is iFraming another website in an effort to further improve the security of the Internet.

At the end of the day, the solution is to set your cookies - specifically the .ASPXAUTH cookie - so that when users navigate the website of the iFrame source the cookies will be passed from page-to-page. This is very important to those who are using FormAuthentication.

The solution requires two changes. Let's look at them now.

Catching multiple exceptions with C#

Published on Jan 26, 2020

Try/catch blocks are a part of my everyday life. But I'm not a fan of catching all exceptions. I prefer handling only the ones I expect to be thrown in specific situations. Of course I can accomplish this with multiple catch blocks, but when they all do common things I would like a simpler way to avoid code duplication.

Deep clone an object with C#

Published on Jan 25, 2020

Cloning is a common thing I need to do in my C# project. The most common case I use this is with my Entity Framework projects. I first fetch my object using a standard Linq query. Once I have this object, EF is now tracking any changes to the object. I want a duplicate object of this so I can track a before and after state, so I want to clone the fetched object. To do this I use JSON.Net nuget package.

What is the difference between String and string in C#?

Published on Jan 24, 2020

Dependent DLL is not getting copied to the build output folder in Visual Studio

Published on Apr 14, 2019

Two different versions of the same DLL with C#

Published on Apr 13, 2019

HtmlHelper Extenstion to convert an object to JSON with C#

Published on Apr 10, 2019

C# Convert any value to a boolean

Published on Apr 5, 2019

C# Ordinal String Extension

Published on Mar 29, 2019

Entity Framework's Code-First with an ObjectContext

Published on Mar 20, 2019

Pass Model or Form Data with MVC when redirecting

Published on Mar 13, 2019

Compile Views with your MVC project

Published on Mar 6, 2019

C# Truncate String Extension

Published on Feb 28, 2019

MVC: Accessing the RouteData inside of your C# code

Published on Feb 27, 2019

C# HtmlExtension to display SVGs

Published on Feb 16, 2019

C# Improving string.IsNullOrEmpty readability

Published on Feb 5, 2019

C# Convert date from UTC to EST

Published on Jun 7, 2017

How to return a CSV from ASP.NET Web API using C#

Published on May 4, 2017

Advanced Automatic Ninject Bindings

Published on Jan 13, 2014

Automatic Ninject Bindings

Published on Jan 7, 2014

Automapper Performance Testing

Published on May 27, 2013

Why the Repository Pattern

Published on May 20, 2013

Entity Framework Beginnerís Guide Done Right

Published on May 13, 2013

Why Java Makes Me Tremble In My Boots

Published on May 6, 2013

My First Experiences with Kinect for Windows - @KinectWindows

Published on Mar 5, 2013

Javascript, the Back Button, and Windows Phone 8 Development

Published on Feb 18, 2013

The Best Way to Prevent SQL Injection

Published on Sep 19, 2012