August 15th, 2016

Generalize a method to read any master table with C# and Dapper

On a web page or application form, it is common to have different master data like Country, State…etc. available in dropdownlist, listbox or any other control. It is needed to read all master data from database and bind to proper controls. This post explains different ways to read master tables with C# and Dapper.

August 15th, 2016

ASP.NET Core Identity: Allow Login with either Email or Username

Do you want to allow user to login with either Username or Email address? ASP.NET Identity uses Username for Signin verification and In default Core template, Email is used as Username. In this post, we will change ASP.NET Core Identity setup to allow both Username and Email on login.

Assumptions:
1. Username is unique for each user. It is either input by user or generated by application on registration.
2. No @ symbol allowed in Username.

July 17th, 2016

ASP.NET Core MVC: Enums with Select TagHelper

In this post, we will see how to use select tag helper in ASP.NET Core MVC and how to bind select tag helper to model data or enum values. The following environment is used for this post:

ASP.NET Core 1.0.1
Dapper 1.50.2
Visual Studio 2015 update 3

For the demo, let us assume we have following Department enum

July 17th, 2016

PostgreSQL Enum, C# and Dapper

Error: column "Gender" is of type enum but expression is of type text.

Are you getting this error when you are using enum datatype in PostgreSQL database? This blog post explains how to fix the error with C# and Dapper. The following environment is used for this post:

July 16th, 2016

ASP.NET Core Identity: Add Roles on Application Startup

In ASP.NET Core application, you want to seed roles and users in the database. This post explains how to add Roles on application startup using ASP.NET Core Identity. It is written in following environment:

ASP.NET Core 1.0.1
Postgresql 9.5.4 database
Npgsql 3.1.9
Dapper 1.50.2
Visual Studio 2015 update 3
Identity.Dapper

April 10th, 2016

Visual Studio Code: Setting Environment Variable for Tasks

Visual Studio Code (VSCode) is a lightweight, open-source code editor and available on Linux, Mac OSX, and Windows. One of the key features of Visual Studio Code is its great debugging support for Node.js (JavaScript and TypeScript) and another feature is to run Tasks(Grunt, Gulp, MSBuild…etc.) from the IDE. If you are new to VSCode, I would recommend to see following video which shows how to debug Node.js app, put break-point and use watch window, use environment variable in Visual Studio Code editor:

March 22nd, 2016

How to display SSRS Report in ASP.NET MVC Application

Today, we will explain how to show SSRS reports in ASP.NET MVC application. Suppose you already created awesome SSRS reports and want to use MVC as Report viewing application. Here is your solution.
Open existing application or create new MVC application. You can install reporting package from NuGet.
Go to Tools -> Library Package Manager -> click on Package Manager Console and type following command into command window.

January 7th, 2016

Installing Linux, Apache, MySQL, PHP (LAMP) Stack on Ubuntu 14.04

I was working to setup development environment of this website on Ubuntu 14.04 virtual machine. So decided to write a post on it. This post explains how to install LAMP stack (Linux, Apache, MySQL and PHP) on Ubuntu 14.04.

Installation:

Run following commands:

sudo apt-get update
sudo apt-get install apache2 php5 libapache2-mod-php5 mysql-server libapache2-mod-auth-mysql php5-mysql phpmyadmin
November 5th, 2015

Export Data to Excel (.xls, .xlsx) in ASP.NET – C#

In this article, we will see different ways to export data to Excel from a web application. It is very common task for web developers. Here are different approaches to do it in ASP.NETC#:

Approach 1:

Using the Excel PIA (primary interop assemblies) to generate a spreadsheet server-side.

It needs Microsoft Office suite installed on your server which is not good. So it is NOT recommended.

August 27th, 2015

CRUD with Multiple File Upload, ASP.NET MVC 5 and EF 6

This tutorial explains the following things in ASP.NET MVC:
1. How to upload multiple files using HTML5 multiple file input with additional model data.
2. How to save files to a specific path on the server (Not in database).
3. How to allow to upload file with same name. Different users can upload files with same name.
4. How to download the uploaded file.
5. How to manage files in edit mode.
6. How to use Entity Framework for CRUD operations with parent child table structure.

May 21st, 2015

A Better Way To Manage ASP.NET Session With Generic Wrapper

Before we get started, let us see the general way to use Session in ASP.NET

if (Session["UserName"] == null) 
{ 
    LabelUserName.Text = "Anonymous"; 
} 
else 
{ 
    LabelUserName.Text = (string)Session["UserName"]; 
} 

You can feel some drawbacks e.g. to check null reference, type safety, to cast object..etc.

Now add following class and see how it solves the issues: