Posts

Showing posts from 2021

SurfaceR with SignalR and .NET 5

Image
Introduction Finally I pulled this off. I made this SurfaceR which is a cool/fun project for my portfolio using SignalR and .NET 5. Let me give you a summary what is this all about!! This is a Web App which has a cube in it made with raw HTML5 and CSS3 and the 3D rotation of the Cube is done by a remote device which sends data through SignalR. It has two modes one is where you can use a mobile device where it captures the Device orientation and rotates the cube accordingly. Also you can control its X,Y and Z axis rotation with a Slider remote also. How It Works? The SignalR connection is made with the two devices. When the Device 1 has the Cube and the Device 2 has the remote, if not you can use two separate browser windows in a PC for testing.  When the Device 2 orientation changes it sends the X,Y and Z info through signalR and the Cube on the Device 1 is rotated accordingly.  It was fun to make, its hosted on Microsoft Azure, you can check it out and Tell me what do you think about

Use SCSS with ASP.NET Core 5.x or 3.X

Image
Here we will see how we can use SCSS or SASS with ASP.NET Core 3.X or 5.X Here is the step to step guide for using SCSS in ASP.NET Core. Step 1: Install sass as global using npm: npm install --global sass Bash Copy Step 2: Create a new ASP.NET Core project , choose MVC or Razor Pages Add a SCSS file to the Web app, here I have added test.scss to the wwwroot/css folder. Add the following lines to the .csproj file to enable SCSS to CSS compilation in the web app. For  node-sass  and  ruby-sass  write this: sass --no-source-map $( ProjectDir ) wwwroot/css/test2.scss $( ProjectDir ) wwwroot/css/test2.css Bash Copy If you're using  dart-sass If you're using dart-sass the usage is --no-source-map sass --no-source-map $( ProjectDir ) wwwroot/css/test2.scss $( ProjectDir ) wwwroot/css/test2.css Bash Copy   < Target Name = " ScsstoCss " BeforeTargets = " Build " > < Exec Command = " mkdir $(ProjectDir)wwwroot/css " Condition = " !Exist

Find Duplicate files by computing Hash in C#

Image
 Here we will try to find the duplicate files by its content in it with computing its hash. If you copy the file several times and change the file name still it will scan and can detect that its a duplicate file. I will use .NET 5 and C# 9 here. let me show you how ​ using System ; using System . IO ; using System . Linq ; using System . Security . Cryptography ; using System . Text ; namespace DupTest { class Program { static void Main ( ) { //Your path here string dir = @"C:\Users\priti\Documents\Microsoft.WindowsSoundRecorder_8wekyb3d8bbwe!App\Sound recordings" ; var fileinfos = Directory . GetFiles ( dir ) . Select ( x = > new { FileName = x , Hash = GetStringFromBytes ( GetHashValue ( x ) ) } ) ; var group_infos = fileinfos . GroupBy ( x = > x . Hash ) . ToList ( ) ; foreach ( var g in group_infos ) {

How to use View Components In ASP.NET Core 5.0 MVC?

Image
  View Components In ASP.NET Core 5.0 MVC The concept of ViewComponet in Asp.Net Core 5 MVC is very similar to a PartialView but it has more potential in it.  ViewComponet renders a small chunk of view which is not a part of the controller or the HTTP life cycle.  Typical usage Additonal product suggestions Extra navigation menu Recently added posts  A Small notice that has to be rendered in every page Sidebar content How to create a ViewComponent? Derive a class from ViewComponent public class Options : ViewComponent { } C# Copy Decorate the class using [ViewComponent] attribute [ ViewComponent ( Name = "Options" ) ] public class Options : ViewComponent { public IViewComponentResult Invoke ( ) { return View ( ) ; } } C# Copy Name the class ViewComponent as subfix public class OptionsViewComponent : ViewComponent { public IViewComponentResult Invoke ( ) { return View ( ) ; } } C# Copy View search path The runti

Change the Primary Key for User table in Asp.NET Core Identity

Image
  Change the Primary Key for User table in Asp.NET Core Identity Goal Here we will change the default primary key for the user table Asp.Net Core Identity in .NET 5. We will change the primary key from string to int. Please use this when you are using a developement database. This tutorial uses .NET 5 and EF Core 5.0.8 Create a new project Create a new project of type ASP.NET Core 5.0 with enabling authentication type as Individual Accounts. When we are trying to customizing things in the Identity framework we may need to add new fields , change the default design and much more. The Identityframework uses Code first approach so we can customize more. For this project I will use SQLite with EntityFrameworkCore version 5.0.8 but you can use SQL Server or any. Remove the migration Use the command remove-migration to remove the default created Migration remove-migration Bash Copy Add a new Class named AppUser Inheriting from identityUser public class AppUser : IdentityUser < int >