Giter VIP home page Giter VIP logo

iatc-webapi's Introduction

IATC-WebAPI

  • ASP.NET Core WebAPI Course from IAmTimCorey.com
  • Check commits for progress throughout the course, and/or notes.
  • Built on Rider & VS

Mac & Linux Dev Environment

Commands

dotnet new webapi -lang "c#" -n "S5L2-Sandbox" -f "net7.0" -o S5L2-Sandbox -d -v diag

  • Note here, .\ was not used when sepcifying output directory, usually, just -n is enough, it will automatically create directory, use -o if you want folder name to be different, or when grouping projects under specific folders.

dotnet sln add S5L2-Sandbox/S5L2-Sandbox.csproj

  • again, see how .\ was omitted as we are in the same directory, this is different in windows.

dotnet run --project S5L2-Sandbox --launch-profile "https"

  • the command already looks for .csproj file, so just passing the directory here is fine.

Manage user Secrets

  • IConfiguration gets injected during WebApplication.CreateBuilder(); IConfiguration itself not only reads from appsettings.json but other places too. such as:
    • Environment Variables
    • Command Line Arguments
    • User Secrets
    • Azure Key Vault
    • 3rd Party Providers and Databases
    • User Secrets & Custom .JSON files (you can add files in IConfigurationBuilder)
  • It seems changes to the appsettings.json file are reflected instantly in the app, might even auto restart web server gracefully
  • There already is an extension that allows managing user secrets in VSCode, code is taken from here

    https://github.com/AdrianWilczynski/UserSecrets/blob/master/src/secretsJson.ts#L5

export function getSecretsPath(id: string) {
    const platform = os.platform();

    if (platform === 'win32') {
        return path.join(os.homedir(), 'AppData', 'Roaming', 'Microsoft', 'UserSecrets', id, 'secrets.json');
    } else if (platform === 'linux' || platform === 'darwin') {
        return path.join(os.homedir(), '.microsoft', 'usersecrets', id, 'secrets.json');
    } else {
        return;
    }
}
  • On a mac, it falls under second option, darwin, same as linux. There seems to be no active development on the extension, so for now it is avoided. But we will use the information on it, as it seems to be working.

  • Looking at the code above, the location for the secrets.json is protected under the user account, so

    โ€ƒWindows :

    ~/Appdata/Roaming/Microsoft/UserSecrets/{GUID}/secrets.json

    โ€ƒLinux | Mac :

    ~/.microsoft/usersecrets/{GUID}/secrets.json

  • In order to user Secrets.json, the following commands are used:

    dotnet user-secrets init

    • This will add the guid to the specific projects csproj file, so you need to be in a project directory alrady when running the command or if in solution just pass --project flag with directory with a .csproj file.
    • However a file is not yet created, so you need to set example value to create the file and open it in vscode.

      dotnet user-secrets set "initSecret" "0"

Projects

  • Section-3-Lesson-2:
    • ASP.NET Core Web API
  • Section-3-Lesson-8:
    • TBC
    • Injected Razor Pages
  • Section-5-Lesson-2:
    • ASP.NET Core Web API

Notes

[From Section-5-Lesson-2]

  • Authentication Types (From Project Creation):
    • Windows Identity Platform:
      • Azure Active Directory BSC
    • Windows Authentication:
      • using windows accounts or AD (including Azure)
    • Auth0
  • Storing Secrets
    • right click project secrets.json (depends IDE)
  • If single HttpGet Action, and name not specified, will auto direct for class.
  • If multiple HttpGet with no name in same class, will cause ambigious name.
  • can be added to appsettings, if want to redirect, and along with app.UseHttpsRedirection in configure middleware for more control

Managing Secrets

  • For local development, storing connections strings,
  • in Rider:
    • right click project > tools > .NET User Secrets
  • in Visual Studio:
    • right click > manage user secrets
  • C:\Users\OT\AppData\Roaming\Microsoft\UserSecrets
  • \32b634af-3239-497e-9b34-4d017d575078\secrets.json
  • Using dotnet user-secrets
    • dotnet user-secrets -?
    • specific to project, but stored in a protected location for any project in system to access

Commands

  • dotnet user-secrets set "first" "last" -p Section-5-Lesson-2 -v
  • Project file path C:\Users\pironadmin\Desktop\Projects\OTonGitHub\IATC-WebAPI\Section-5-Lesson-2\Section-5-Lesson-2.csproj.
  • Secrets file path C:\Users\pironadmin\AppData\Roaming\Microsoft\UserSecrets\32b634af-3239-497e-9b34-4d017d577777\secrets.json.

iatc-webapi's People

Contributors

ifhaam-csc avatar otongithub avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.