Skip to content

Instantly share code, notes, and snippets.

@hgirish
hgirish / ApplicationUser.cs
Created June 4, 2022 07:05
Update Asp.Net Identity to Latest .net Core Identity, tested with Net6
// https://stackoverflow.com/questions/53878000/how-to-migrate-identity-users-from-a-mvc5-app-to-a-asp-net-core-2-2-app
/* We need a way to differentiate what users are using the new hash version or not.
One way is to add a new property to IdentityUser:
*/
using Microsoft.AspNetCore.Identity;
public class ApplicationUser: IdentityUser
{
@hgirish
hgirish / gist:af92d9449c3dc7da3904ddc3c38407bf
Last active June 3, 2022 04:19
Convert Html.Partial to Partial tag using find replace in VS
Find:
@Html.Partial\(\"(.*)\"\)
Replace:
<partial Name="$1" />
@hgirish
hgirish / get-all-migrations-name.ps1
Created December 17, 2019 07:10
Gets the list of EF migrations from C# aspnet core project
Get-ChildItem -Path . -Filter *.cs | Where-Object { $_.Name -match "^\d{14}_.*\.cs" } | Where-Object Name -NotLike "*Designer*"| Select-Object -ExpandProperty Name | Set-Content -path D:\Downloads\migrations.txt
@hgirish
hgirish / set-ineternet-connection-private.ps1
Created December 10, 2019 19:57
Changes internet connection type to private in windows using powershell
Get-NetConnectionProfile -InterfaceAlias vEthernet* | Set-NetConnectionProfile -NetworkCategory Private
@hgirish
hgirish / IssueClassificationWithMLNetApi.cs
Created December 5, 2019 03:35
Getting Scores and Labels for prediction in multiclass classification with ML .NET
/*
* Based on dotnet github issue https://github.com/dotnet/docs/issues/14265
*/
using Microsoft.ML;
using Microsoft.ML.Data;
using RestaurantViolationsML.Model;
using System;
using System.Collections.Generic;
using System.Linq;
# Using PowerShell, find which process is using the port to solve port in use error.
$portNumber = 1433
Get-Process -Id (Get-NetTCPConnection -LocalPort $portNumber).OwningProcess
$cnname = read-host -prompt "Input Common distinguished name"
if (-Not( $cnname)) {
exit
}
$key = $cnname + ".key"
$crt = $cnname + ".crt"
$pfx = $cnname + ".pfx"
$subj = "/CN=" + $cnname
write-host "Create the certificate and private key"
@hgirish
hgirish / LoadCertificate.cs
Last active August 9, 2019 17:52
Load Certificate for IdentityServer AddSigningCredential
private X509Certificate2 LoadCertificate()
{
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
//foreach (X509Certificate2 certificate in store.Certificates)
//{
// Console.WriteLine(certificate.SubjectName.Name);
//}
@hgirish
hgirish / ModelState_UnitTesting.cs
Created August 5, 2019 00:51
Unit Testing C# AspNet Core Model State Error
[Fact]
public void InvlaldiModel_ReturnsView(){
var controller = new CheckoutController();
controller.ModelState.AddModelError("a", "ModelErrorA");
var order = new Order();
var result = controller.AddressAndPayment(order);
var viewResult = Assert.IsType<ViewResult>(result);
Assert.Null(viewResult.ViewName);
@hgirish
hgirish / gist:a247fcc3f74b9ea1044bdfccc5bffc51
Last active December 13, 2018 20:06
Vue.js router-link css class using bootstrap 4
<nav>
<ul class="nav nav-pills">
<li class="nav-item">
<router-link to="/" class="nav-link" exact-active-class="active"
>Home</router-link
>
</li>
<li class="nav-item">
<router-link
class="nav-link"