OJ Develops

Thoughts, tips, and tricks on software development. .NET | C# | Azure

Managing Lookup Tables with Entity Framework Code First

11 April 2016

Oftentimes in our applications we will have such things as a "lookup table". I am defining a lookup table as a list of relatively fixed or static choices such as status codes, states or provinces, and so on. In this post I will share how I manage lookup tables using Entity Framework.

Read More

Web Scraping with F#

29 March 2016

Web scraping is defined as getting and saving information from an HTML page through a program. In this post we will leverage F# and the HTML type provider to do web scraping.

Read More

On Validation and Database Design

15 March 2016

SQL Server lets us design tables which have constraints and checks in them. Some examples of these constraints / checks are primary key constraints, nullability flags, maximum length flags, and so on. These checks are used to ensure data integrity. Insert, update, and delete commands which will result in an invalid state when executed are not allowed. However, there are some advantages to not using these checks. In this post, we will talk about some of those advantages.

Read More

Strongly-Typed AppSettings

29 February 2016

Application settings for .NET projects provide a way to change the behavior of a program without recompilation. These settings are typically stored as key-value pairs in the web.config or app.config files and can be accessed through the `ConfigurationManager` class provided by the framework. In this post we will be taking configuration access to the next level by providing a strongly-typed wrapper around the ConfigurationManager class.

Read More

Publishing an ASP.NET 5 Project to a Local IIS Server

06 February 2016

Recently I deployed a new ASP.NET 5 web application to a local IIS server. Though there are several online resources available about deployment, I encountered some problems that were difficult to diagnose and fix. In this post I will talk about the general deployment process and the steps I followed for a successful deployment.

Read More

Using AntiForgeryTokens in ASP.NET MVC with AngularJS

10 January 2016

Protection against CSRF (use of AntiForgery tokens) is supported in both the ASP.NET MVC and AngularJS frameworks. However, they have different implementations. What this means is that the default implementation of ASP.NET MVC for AntiForgery tokens will not work out-of-the box on an AngularJS front-end. In this post we will look at this in more detail and come up with a solution to the problem.

Read More

Integrating Custom Validation with ASP.NET MVC ModelState

03 January 2016

One common pattern we see in ASP.NET MVC controller actions is a conditional check for ModelState.IsValid, with different branches getting executed based on whether the result is true or false. The ModelState captures errors arising from data annotations such as `Required` and StringLength. When there are custom validations that cannot be captured using data annotations, what usually happens is that these validations are checked in the success block of ModelState.IsValid. In this post we are going to talk about how to integrate custom validation into ModelState.

Read More

Loading Related Data in Entity Framework

26 December 2015

There are three behaviors that entity framework can use when loading related data. These are lazy loading, eager loading, and explicit loading. The main difference between the three are in when the related data gets loaded and whether it is done behind-the-scenes or explicitly. In this post we will learn about these behaviors and evaluate when one should be used over the other.

Read More

Using AntiForgery Tokens in ASP.NET MVC

19 December 2015

Cross-site Request Forgery (CSRF or XSRF) is a type of cyber attack wherein an attacker makes an HTTP request on a user's behalf without the user's knowledge or consent. If successful, a significant amount of damage can be done, depending on the nature of the request. This kind of attack can be prevented by using antiforgery tokens. In this post, we will talk about how we can prevent CSRF attacks in our ASP.NET MVC applications.

Read More

Creating Custom Html Helper Methods Part 2

05 December 2015

In a previous post we talked about creating custom html helpers. The implementation there involved customizing helpers that already existed in the ASP.NET MVC framework. In this post we will talk about creating our own helpers from scratch. This will allow us to create helpers for any kind of html element and will also provide flexibility on the element building process.

Read More