ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-enabled, internet-connected apps.
Kubernetes ist in der Cloud-Welt allgegenwärtig; nahezu alle Public-Cloud-Anbieter offerieren Kubernetes als Managed Service oder nutzen es intern für ihre PaaS- und Serverless-Dienste. Auch in lokalen Rechenzentren wird Kubernetes häufig eingesetzt und entfaltet dort seine Stärken als Plattform. Obwohl sich die verschiedenen Kubernetes-Distributionen und Managed Services in technischen Details wie Installation und Integration von Netzwerk- und Speicherressourcen unterscheiden, bleibt die Plattform für Anwendungen weitgehend einheitlich. Mit minimalen Konfigurationsanpassungen können Applikationen sowohl in der Cloud als auch in On-Premises-Umgebungen nahtlos betrieben werden.
To inject configuration settings in your ASP.NET Core application, use Microsoft.Extensions.Configuration
and inject IConfiguration
into your page or component. Access configuration values using Configuration["KeyName"]
.
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
<!-- Access configuration value -->
@Configuration["ApplicationInsights:InstrumentationKey"]
For more structured configuration management, use the options pattern with Microsoft.Extensions.Options
. Inject IOptionsMonitor<TOptions>
with @inject
and access configuration values through OptionsAccessor.Value.PropertyName
.
@using Microsoft.Extensions.Options
@inject IOptionsMonitor<ApplicationInsightsOptions> ApplicationInsightsOptionsAccessor
<!-- Access configuration value -->
var instrumentationKey = ApplicationInsightsOptionsAccessor.Value.InstrumentationKey;
For detailed information, refer to the ASP.NET Core documentation on configuration options.
Razor is a concise markup language that integrates server-side code (C# or VB) into ASP.NET web pages seamlessly. It simplifies web development by blending code and HTML, enhancing productivity and maintainability.
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<h1>@ViewData["Title"]</h1>
<p>Welcome to my ASP.NET Core Razor Pages!</p>
In this code snippet, the @page directive specifies the page, @model defines the page's model, and @ViewData displays dynamic data within the Razor Page markup.
Resources
Razor Syntax allows you to embed code (C#) into page views through the use of a few keywords, and then have the C# code be processed and converted at runtime to HTML.
Here are six different ways to run your ASP.NET Core web application:
For more detailed information, check out the guide on 6 different ways to run an asp.net core web application (secretGeek.net)
Before jumping to the solution, let's talk about use cases. Using both tokens and cookies is not a common use case, but it typically comes up when you have a SPA or pure API applications that also need to secure some non-SPA pure Web Browser end points that the server sends directly to the browser. If that content needs to be protected behind authentication you might need Cookie authentication, because you can't do Bearer Token authentication with plain HTML interfaces in the browser.
services.AddAuthentication(options =>
{
// custom scheme defined in .AddPolicyScheme() below
options.DefaultScheme = "JWT_OR_COOKIE";
options.DefaultChallengeScheme = "JWT_OR_COOKIE";
})
.AddCookie("Cookies", options =>
{
options.LoginPath = "/login";
options.ExpireTimeSpan = TimeSpan.FromDays(1);
})
.AddJwtBearer("Bearer", options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = config.JwtToken.Issuer,
ValidateAudience = true,
ValidAudience = config.JwtToken.Audience,
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config.JwtToken.SigningKey))
};
})
Source: Combining Bearer Token and Cookie Authentication in ASP.NET - Rick Strahl's Web Log (west-wind.com)