📗
Everyday Cheat Sheets
  • README
  • Build
    • Architecture
      • API Management
        • Kong
      • Authentication
        • Keycloak
        • Okta
      • Cloud Native
      • Design Patterns
      • Design Principles
      • IaC
      • IoT
      • Message Broker
      • Methods
      • Networking
      • Payment
        • Stripe
      • Testing
    • Code lifecycle (ALM)
      • Automation Pipelines
        • Argo CD
        • CircleCI
        • Flux
        • Keptn
        • Travis
      • Azure DevOps
        • Azure Pipelines
      • Chef
      • GitHub
        • GitHub Actions
      • Nexus
      • Promyze
      • RunDeck
      • SaltStack
      • Sonar
      • Tuleap
    • Containers & Cloud Native
      • Argo Workflows
      • Containerization
        • Docker
          • Docker CLI
        • containerd
        • cri-o
      • CNAB
      • Dapr
      • Envoy
      • Fluentd
      • Knative
      • Kubernetes
        • Cluster API
        • etcd
        • Helm
        • k3d
        • kind
        • Kubectl
        • MetalLB
        • Minikube
      • Open Application Model (OAM)
      • Unleash
    • Data storage
      • MySQL
      • MongoDB
        • Atlas
        • Compass
        • Evergreen
        • MongoDB 4.2
        • MongoDB 5.0
        • MongoDB design
        • MongoDB events
        • MongoDB driver for .NET
        • Ops Manager
        • Realm
      • Oracle
      • Redis
      • SQL Server
      • PostgreSQL
    • Frameworks & libraries
      • Angular
        • Angular CLI
        • Angular events
      • .NET
        • ASP.NET Core
        • Blazor
        • .NET 5.0
        • .NET 6.0
        • .NET CLI
        • .NET Core
        • .NET Events
        • .NET Logging
        • .NET Testing
        • NuGet
        • WPF
        • Xamarin
      • gRPC
      • Ionic
      • Jekyll
      • Node.js
        • Express
        • NPM
      • React
        • React Native
      • Redux
    • IDE
      • Visual Studio 2022
    • Languages
      • C#
        • C# 8.0
      • ECMAScript
      • GraphQL
      • JavaScript
        • webpack
        • Yarn
      • MS-DOS
      • PHP
      • PowerShell
      • Python
      • Swagger
      • TypeScript
    • Messaging
      • Azure Service Bus
      • RabbitMQ
    • Testing
    • Workstation
      • QGIS
      • Visual Studio 2019
      • Windows 10
      • Windows Subsystem for Linux
  • Collaborate
    • Marp
    • Microsoft 365
      • Microsoft Graph
      • SharePoint Framework
        • Fluent UI
        • SharePoint Framework UI components
  • Run
    • Cloud computing
      • Alibaba
      • AWS
      • Azure
        • Azure AD
        • Azure CLI
        • Azure Container Registry
        • Azure Portal
        • Azure Service Bus
      • Firebase
      • OVH
    • Hardware
      • Single-board computers
        • Odroid
        • Raspberry Pi
    • Infrastructure automation
      • Azure Resource Manager
      • Packer
      • Pulumi
      • Puppet
      • Terraform
        • HCL
        • Terraform CLI
        • Terraform Providers
    • Networking
      • HAProxy
      • nginx
    • Observability
      • Grafana Labs
        • Grafana
        • Loki
        • Tempo
      • OpenTelemetry
      • Prometheus
      • Splunk
    • Security
      • Falco
    • Systems
      • Linux
        • CentOS
        • eBPF
        • Linux Kernel
        • Rocky
        • Ubuntu
      • Windows Server
    • Virtualization
      • Hyper-V
      • Vagrant
  • Optimize
    • DevOps
  • Join
    • Companies
      • HashiCorp
Powered by GitBook
On this page
  • Learn
  • Fundamentals
  • Deep dive
  • Recipes
  • Swagger
  • Logging
  • Dispose
  • Performance
  • OData
  • Securing
  • Testing
  • Versioning
  • Health checks
  • Packaging
  • Controller action status code
  • Authentication

Was this helpful?

Export as PDF
  1. Build
  2. Frameworks & libraries
  3. .NET

ASP.NET Core

Previous.NETNextBlazor

Last updated 1 year ago

Was this helpful?

ASP.NET Core is the open-source version of ASP.NET, that runs on Windows, Linux, macOS, and Docker.

→ ,

Learn

Fundamentals

Deep dive

Recipes

Swagger

Logging

Dispose

Performance

OData

Securing

Testing

Versioning

Health checks

Packaging

WebPack

Articles to review:

Controller action status code

public IActionResult Post([FromBody]string action)
{
    if (...)
    {
        return StatusCode(423);
    }

    return Ok(new ... {});
  }
}

Authentication

Use Azure Directory

  • Edit csproj file

<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="2.1.1" />
  • Edit appsettings.json file

"AzureAd": {
  "Instance": "https://login.microsoftonline.com/",
  "Domain": "<domainName>",
  "TenantId": "<tenantId>",
  "ClientId": "<clientId>",
  "CallbackPath": "/signin-oidc"
},
  • Edit Startup.cs:

// in ConfigureServices()

services.Configure<CookiePolicyOptions>(options =>
{
    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
    options.CheckConsentNeeded = context => true;
    options.MinimumSameSitePolicy = SameSiteMode.None;
});

services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
    .AddAzureAD(options => Configuration.Bind("AzureAd", options));

services
    .AddMvc(options =>
    {
        var policy = new AuthorizationPolicyBuilder()
            .RequireAuthenticatedUser()
            .Build();
        options.Filters.Add(new AuthorizeFilter(policy));
    })
    .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

// in Configure()

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
else
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseCookiePolicy();

app.UseAuthentication();

- 2018-05-23

Go to Azure Portal and create an application in Azure Active Directory:

Examples: or run dotnet new mvc -o dotnetadauth --auth SingleOrg --client-id <clientId> --tenant-id <tenantId> --domain <domainName>

docs
code
Application startup
Configuration
Dependency Injection
Error handling
Host and deploy
Kestrel web server in ASP.NET Core
Host ASP.NET Core on Windows with IIS
Filters
Filters
Dependency Injection in Action Filters
Identity
Integration tests
Logging
Multiple environments
Routing
Web server implementations
Performance Best Practices
Performance and reliability
The shared framework
Get started with Swashbuckle and ASP.NET Core
ASP.NET Core Logging with Azure App Service and Serilog
Four ways to dispose IDisposables in ASP.NET Core
ASP.NET Core: Saturating 10GbE at 7+ million request/s
TechEmpower - Web Framework Benchmarks
Channel 9 - Supercharging your Web APIs with OData and ASP.NET Core
Securing ASP.NET Core 2.0 Applications with JWTs
Integration tests in ASP.NET Core
Real Browser Integration Testing with Selenium Standalone, Chrome, and ASP.NET Core 2.1
IntegrationTestsSample
aspnet-api-versioning
Blog of Pi
Xabaril/AspNetCore.Diagnostics.HealthChecks
A complete containerized .NET Core Application microservice that is as small as possible
Setting up Webpack in ASP.NET Core
ReactJs Webpack and ASP.NET Core
How to use Webpack in ASP.Net core projects; a basic React Template sample
BUNDLING IN .NET CORE MVC APPLICATIONS WITH WEBPACK
How to include Bootstrap in your project with Webpack
Integrating Azure AD into an ASP.NET Core web app
GitHub Azure-Samples/active-directory-dotnet-webapp-openidconnect-aspnetcore