Custom error pages in ASP.NET MVC

Excellent blog post by Ben Foster:
Custom error pages in ASP.NET MVC. Easy, right? – Ben Foster

My extra take on it was to create content in the static .html pages and use an iframe inside the aspx based pages (to reuse the content easily).

E.g: (my 500 error page is named Error500.aspx)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Error500.aspx.cs" Inherits="Error500" %>
<% Response.StatusCode = 500; %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>An error has occurred - 500</title>
    <style>iframe, html, body { height: 100%; width: 100%; margin: 0; border: 0; padding: 0; }</style>
</head>
<body>
    <iframe src="Error500.html"></iframe>
</body>
</html>

 

ASP.NET Core Razor Pages – Simpler ASP.NET MVC Apps with Razor Pages

“Razor Pages are a new feature in ASP.NET Core 2.0. They provide a simpler way to organize code within ASP.NET Core applications, keeping implementation logic and view models closer to the view implementation code. They also offer a simpler way to get started developing ASP.NET Core apps, but that doesn’t mean you should dismiss them if you’re an experienced .NET developer. You can also use Razor Pages to improve the organization of larger and more complex ASP.NET Core apps.”

Source: ASP.NET Core – Simpler ASP.NET MVC Apps with Razor Pages

Architect modern web applications with ASP.NET Core and Azure | Microsoft Docs

.NET Core and ASP.NET Core offer several advantages over traditional .NET development. You should use .NET Core for your server applications if some or all of the following are important to your application’s success:

  • Cross-platform support

  • Use of microservices
  • Use of Docker containers
  • High performance and scalability requirements
  • Side-by-side versioning of .NET versions by application on the same server

PDF:
https://raw.githubusercontent.com/dotnet-architecture/eShopOnWeb/master/docs/Architecting%20Modern%20Web%20Applications%20with%20ASP.NET%20Core%20and%20Azure.pdf

Online: Architect modern web applications with ASP.NET Core and Azure | Microsoft Docs

Choose between .NET Core and .NET Framework for server apps | Microsoft Docs

There are two supported implementations for building server-side applications with .NET: .NET Framework and .NET Core. Both share many of the same components and you can share code across the two. However, there are fundamental differences between the two and your choice depends on what you want to accomplish. This article provides guidance on when to use each.

Source: Choose between .NET Core and .NET Framework for server apps | Microsoft Docs

How to fetch the row count for all tables in a SQL SERVER database

The following SQL will get you the row count of all tables in a database:

CREATE TABLE #counts
(
    table_name varchar(255),
    row_count int
)

EXEC sp_MSForEachTable @command1='INSERT #counts (table_name, row_count) SELECT ''?'', COUNT(*) FROM ?'
SELECT table_name, row_count FROM #counts ORDER BY table_name, row_count DESC
DROP TABLE #counts

The output will be a list of tables and their row counts.

If you just want the total row count across the whole database, appending:

SELECT SUM(row_count) AS total_row_count FROM #counts

will get you a single value for the total number of rows in the whole database.

Source: How to fetch the row count for all tables in a SQL SERVER database – Stack Overflow

How to migrate a SQL Server database to a lower version

…there are a few options that can help us to downgrade the database from a higher version of SQL Server to a lower version SQL Server. These options include:

  • Generate Scripts wizard of SQL Server Management Studio
  • SQL Server Integration Services
  • Custom scripting and BCP

In this tip we will use the Generate Scripts wizard of SQL Server Management Studio.

Source: How to migrate a SQL Server database to a lower version

Keeping your ASP.NET WebAPI Controllers lean with the use of Filters | Digital Affinity

“In a constant battle to reduce the amount of duplication and technical debt in the code I write, I am always revisiting code and looking at how I can reduce the amount of maintenance work I need to perform.”

See source: Keeping your ASP.NET WebAPI Controllers lean with the use of Filters | Digital Affinity

Batch convert a folder of images from png to jpg

I had a bunch of png images in several subfolders which I wanted to convert into jpg.

I used the command line tool ImageMagick for Windows, which is free and can be downloaded here:
Download @ ImageMagick

This command will convert all images in the folder and its subfolders from png to jpg with quality 65. The converted files will get the same filename but with jpg extension:

for /R %f in (*.png) do ( convert -quality 65 "%f" "%~npf.jpg" )

convert is the ImageMagick command running, for /R is used for looping recursively.

Use this command when done to remove all the source png files:

del *.png /s

This will delete all png files in this folder and all subfolders.