Skip to content

Instantly share code, notes, and snippets.

@nagasudhirpulla
Last active March 11, 2018 00:37
Show Gist options
  • Save nagasudhirpulla/af95557ed8d07b1fe8c374c286a91222 to your computer and use it in GitHub Desktop.
Save nagasudhirpulla/af95557ed8d07b1fe8c374c286a91222 to your computer and use it in GitHub Desktop.
.NET Core notes

Docs link -- https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?tabs=visual-studio%2Caspnetcore2x

Storing user secrets in environment variables and userSecrets

https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?tabs=visual-studio

We can create a secrets.json file in visual studio by right click on solution Manage User Secrets and then write the following in the secrets.json file

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=_CHANGE_ME;Trusted_Connection=True;MultipleActiveResultSets=true"
  }
}

Enforce HTTPS globally in ConfigureServices and Configure

https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl

To create a new razor app with security enabled, use

donet new --auth Individual -o AuthLearnCoreApp

The template already uses a IdentityUser Model with all the necessary attributes and checks for the user model in the database.

IdentityUser already has strong assumptions about the table names and column names of the users table. Hence to change the default column and table names, override the onModelCreating method in the ApplicationDBContext class https://stackoverflow.com/questions/19460386/how-can-i-change-the-table-names-when-using-visual-studio-2013-asp-net-identity

We can use ignore class members for column mapping using the NotMapped annotation or using the modelBuilder.Entity<Customer>().Ignore(t => t.LastName); command in during the onModelCreating method

https://stackoverflow.com/questions/10385248/ignoring-a-class-property-in-entity-framework-4-1-code-first

Procedure to add Google authentication -- https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?tabs=aspnetcore2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment