Posts

Showing posts with the label ASP.NET

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Image
As you know ASP.NET Core Identity (table structure) is different from what we had earlier in ASP.NET Identity. Actually the identity system which we have today with .NET Core is very mature and continuously evolved be it ASP.NET Membership, ASP.NET Identity 1, ASP.NET Identity 2 and now ASP.NET Core Identity.

Recently I had to migrate few application to ASP.NET Core and similar its identity database. Because the table schema is changed, i had to re-think and create migration script which I would like to share with you today.

It is very simple and easy, just three step and I had everything ready:

STEP 1 : Change name of existing tables
STEP 2 : Create ASP.NET Core Identity tables
STEP 3 : Migrate data from old tables (ASP.NET Identity) to new tables (ASP.NET Core Identity)


Script: https://gist.github.com/itorian/c699e8534b392a6c726ec66c48100072

You should also watch my video, where I demoed migration.


Lambda two tables and three tables inner join code samples

In this blog post you will learn inner join using lambda queries. There will be two samples, in first sample you will see how you can join two tables and in second sample you will see how you can extend even further to join three tables and so on.

I will sample in-memory data, but the same implementation will work with IQueryable (lazy query) too.

Here's the code snippet:-

namespace ConsoleApp1 { classProgram     { staticvoid Main()         { var table1 = new List<Table1>();             table1.Add(new Table1 { Id = 1, Name = "Name 1", Address = "Address 1" });             table1.Add(new Table1 { Id = 2, Name = "Name 2", Address = "Address 2" });             table1.Add(new Table1 { Id = 3, Name = "Name 3", Address = "Address 3" });             table1.Add(new Table1 { Id = 4, Name = "Name 4", Address = "Address 4" });
var table2 = new List<Table2>();             table2.Add(new Table2 { Id = 1, Email = &q…

How to move web.config connectionStrings in a separate web.config file ?

In this post you will learn how to create a separate web.config file in ASP.NET or MVC to store development and production versions of connection strings.

Step 1. Create a PrivateConn.config file on root with below code

<connectionStrings>   <addname="DataConn1"connectionString="Data Source=server;Initial Catalog=database1;Persist Security Info=True;User ID=sa;Password=xxxx;MultipleActiveResultSets=True;App=EntityFramework"providerName="System.Data.SqlClient" />   <addname="DataConn2"connectionString="Data Source=server;Initial Catalog=database2;Persist Security Info=True;User ID=sa;Password=xxxx;MultipleActiveResultSets=True;App=EntityFramework"providerName="System.Data.SqlClient" />
</connectionStrings>
Step 2. Open main web.config file (on application root) and then define new config file path, as given below

<configuration>   ....other codes....   <connectionStringsconfigSource="PrivateCo…

How to move web.config appSettings in a separate web.config file ?

In this post you will learn how to create a separate web.config file in ASP.NET or MVC to store development and production versions of application settings.

Step 1. Create a Private.config file on root with below code

<appSettings>   <addkey="data1"value="value1"/>   <addkey="data2"value="value2"/>
</appSettings>
Step 2. Open main web.config file (on application root) and then define file path with appSettings start tag, as given below

<configuration>   ....other codes   <appSettingsfile="PrivateSettings.config">     <addkey="webpages:Version"value="3.0.0.0"/>     <addkey="webpages:Enabled"value="false"/>

Caching in MVC with Donut Caching - excluding caching login

The main purpose of using caching is to dramatically improve the performance of your application. This is nothing but output caching that means whatever you see is cached, and exact similar things is display to everyone.
I recommend you to read Output Caching in MVC post before you read here, because you should be very careful when using any caching mechanism. Or, if you already know output caching, keep reading here only.
Biggest problem you face
If you display user login status on page which you want to cache, then you need to be careful. With output cache attribute [OutputCache(....)] caches everything on page and it will not exclude caching of some portion like login status.
In the situation, the best caching library you should use is Donut Caching (aka Donut Output Caching). Let’s understand its uses.
Using Donut Caching
The best way to add donut caching to your MVC project is to use the NuGet package. From within Visual Studio, select Tools | Library Package Manager and then choo…

Sorting in WebAPI - a generic way to apply sorting

Image
In this post you will learn how to implement sorting functionality in WebAPI so that client can ask for sorted data by sending columns names through query string. Client can send more than one short parameters and request for ascending or descending data in response. Sorting functionality should be generic enough so that we can reuse it.

Field level data selection in WebAPI

Image
In this post you will learn how to implement field level data selection functionality in WebAPI so that client can ask for less data by sending individual columns names through query strings variable fields.

Upload video on YouTube in ASP.NET or MVC

Image
In this post you will learn how to upload video on YouTube from your application. I’ve used ASP.NET Web Forms as well as MVC bits to implement all functionality easily. You can achieve similar functionality ASP.NET Web Forms or MVC alone.

Write on Existing Image

Image
In this blog post you will learn all about writing text or image on existing image. I will be developing this in ASP.NET Web Forms, but you can achieve this functionality in MVC or windows forms as well. I’ve posted another blog post which generates QR Code. Actually all this was part of my recent requirement which I would like share with you.

QR Code Generation and Verification

Image
In this blog post you will learn all about QR Code, starting from requirement to generation to verification. I am going to develop this in C# and in ASP.NET Web Forms, but you can use it with MVC, Desktop Apps etc. I will be using MessagingToolkit.QRCode open source library for everything here.

Search in selected file types Visual Studio

Image
This is a very important feature which is worth useful when making necessary changes that may match in multiples file types but you are only supposed to change in selective files types.

Roslyn csc.exe and vbc.exe deployment on shared hosting

Roslyn compilation is now default with .NET 4.5 means if you create any web application either Web Forms or MVC using .NET 4.5 you get this compilations bits pre-installed in your project.
Why use Roslyn compilation?
In nutshell, this enables many features which is very useful when developing application as well as when application is deployed on server.

Stop Debugging stops IIS Express hence application stop running in browser in Visual Studio 2015

Image
Note: This was a bug with Visual Studio 2015 Update 2 which is officially mentioned and fixed in Update 3.Read more here.

This is not a bug but as a web developer I personally expect when debugging stops browser should keep running through IIS Express instance. Next time, I make change in Visual Studio code then do a build and refresh browser, I’m addicted this way.

The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'

Image
Error: The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'
I received above error on my production machine after deploying new database for a web application. I have SQL Server 2008 R2 installed and to deploy database I created query file (.sql) schema with data. After that I deployed web application properly.

MVC client side validation not working with modal or Bootstrap model

Recently in my one of the MVC Project, dynamically loaded content on Bootstrap modal client side validation was not working. By any chance if you face same issue this post is important for you.

An error occurred when trying to create a controller of type 'AlbumsController'. Make sure that the controller has a parameterless public constructor.

By any chance if you see below error, please use below resolving instruction to overcome.
An error occurred when trying to create a controller of type 'AlbumsController'. Make sure that the controller has a parameterless public constructor.

LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression

Image
LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression
First of all look at the screenshot of the error page

Export table data into excel file

Exporting table data (DOM data) on the HTML page to excel file is a very common requirement. The simplest approach or say the completely client side approach to achieve this is to export the DOM data using client side scripts.

'CompareAttribute' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.CompareAttribute' and 'System.Web.Mvc.CompareAttribute'

Image
'CompareAttribute' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.CompareAttribute' and 'System.Web.Mvc.CompareAttribute'

Remove Header & Footer from Print Preview in Google Chrome

Image
Recently I had a requirement when one printing the web page should not display header and footer, basically they are automatically inserted by the browsers. Here is what this looks like:

Popular posts from this blog