Add identity into an ASP.NET Core 2.1 MVC project and maintain full control of the Identity UI

To maintain full control over the Identity UI in an ASP.NET Core 2.1 MVC project, scaffold the identity using the Windows version of Visual Studio 2017. Scaffold the Identity Right click the web application project and select Add, New Scaffolded Item… On the left side of the Add Scaffold dialog select Identity, and click the Add button […]

Add jQuery DataTables grid to an ASP.NET Core MVC web application

ASP.NET does not provide sortable, searchable tables. jQuery DataTables is a popular way to display user-friendly data in an ASP.NET Core MVC web application. Set up the environment Add the System.Linq.Dynamic.Core NuGet package to the web application Add the JsonOptions to the Startup.cs file using Newtonsoft.Json.Serialization; Add the AddJsonOptions to the services.AddMvc() section in the ConfigureServices() method of the Startup.cs file .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); Add […]

Error unprotecting the session cookie in an ASP.NET Core MVC application.

The new ASP.NET Core MVC framework automatically displays a message for the user to accept the application’s privacy policy. The default message is “Use this space to summarize your privacy and cookie use policy.” No cookies are saved in the user’s browser until they click the Accept button. Even after accepting the terms, if the browser […]

Set the environment for an ASP.NET Core MVC web application

When the ASP.NET Core MVC web application starts, reads the name of the environment for an environment variable of the host computer. The compiled application contains the configuration for all supported environments, making possible to build and deploy the same artifact in every environment. If the ASPNETCORE_ENVIRONMENT environment variable is not defined, the Production environment settings are […]

Enable .NET Core Entity Framework Linq query execution

When we create a new .NET Core class it only contains the using System; reference. To enable Linq database queries in a .NET Core project, add using System.Linq; using System; using System.Linq; To enable the usage of .Include() in the Linq queries, add using Microsoft.EntityFrameworkCore;  

Return values to the controller in the model from the ASP.NET MVC view

When we create an ASP.NET MVC web application, the model (an object) is the easiest way to return values from the view to the controller. For the view to be able to return the values in the model, make sure the model contains properties, not fields, for every value with { get; set; } public class MyViewModel { public […]

Reverse engineer a database with AspNetCore in Visual Studio

For some reason the .NETCore designers did not think, that developers want to follow best practices by separating the data layer from the presentation layer. The Entity framework out of the box only works if the database is accessed from the main application project. When we try to reverse engineer a PostgreSQL database from a […]

The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

When I made changes to the web.config file of an ASP.Net C# application, I have accidentally deleted a comma, and I started to get the runtime error message: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) Make sure all necessary commas are there in the config files, Visual Studio does not […]

{“error”:”Entity type ‘AspNetUserRoles’ has composite primary key defined with data annotations. To set composite primary key, use fluent API.”}

When a database table has composite keys (multiple columns are in the key) you cannot use the usual key definition [Key] [Display(Name = “UserId”)] public string UserId { get; set; } [Key] [Display(Name = “RoleId”)] public string RoleId { get; set; } When you run the application you get the error message: {“error”:”Entity type ‘AspNetUserRoles’ has composite […]

Generate SQL script from Entity Framework migration script

It is not recommended to execute Entity Framework migration scripts in production, It is important that you execute all SQL steps manually on the production database section-by-section to immediately see the result and be able to recover in case a destructive action goes wrong. The Visual Studio .NET application templates contain Entity Framework migration scripts to […]