75 liens privés
In this article, let's go through one of the most searched queries on Google, "File Upload in ASP.NET Core MVC". Uploading Images or other documents is a very basic and common requirement when it comes to building anything from a simple application to an enterprise-level solution. Let's build a small application with which you could upload files of any type to a file system location or to a centralized database table.
This article explains how to improve your ASP.NET Core sites' e-mailing capabilities to make things easier to manage and improve stability.
This is a sample appsettings.json file:
{
"ExampleConfig": {
"ValueA": "aaa",
"ValueB": "https://example.com",
"ValueC": 1234
}
}
This is our example model which we want to load from the configuration:
public class ExampleConfig
{
public string ValueA { get; set; }
public Uri ValueB { get; set; }
public int ValueC { get; set; }
}
Here’s how I read the model from the configuration:
public class ExampleCommandHandler
{
private readonly IConfiguration _configuration;
public ExampleCommandHandler(IConfiguration configuration)
{
_configuration = configuration;
}
public Task Handle(ExampleCommand)
{
var exampleConfig = _configuration
.GetSection(nameof(ExampleConfig))
.Get<ExampleConfig>()
?? throw new ConfigurationException(nameof(ExampleConfig));
// ...
}
}
There is one thing you need to watch out for. To call the Get<T> method, use Microsoft.Extensions.Configuration.Binder NuGet package.
var currentlight = getcurrentlight();
string action = currentlight switch
{
TrafficLight.red => "stop",
TrafficLight.orange => "slow down",
TrafficLight.green => "go",
_ => "unknown",
}
Razor is a markup syntax for embedding .NET based code into webpages. It includes Razor markup, C#,... Tagged with dotnet, csharp, webdev.
In this post
Kamil Grzybek Personal Site
verifier qu'il s'agit que la modification et la sauvegarde des l'événement se fait dans la même transaction.
:card_index: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js. - GitHub - bchavez/Bogus: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js.
The [Column(TypeName = "decimal(18, 2)")] data annotation is required so Entity Framework Core can correctly map Price to currency in the database. For more information, see Data Types.
source : https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/tutorials/razor-pages/validation.md
High performance understanding for stack traces (Make error logs more productive) - GitHub - benaadams/Ben.Demystifier: High performance understanding for stack traces (Make error logs more productive)
DateTime dateTime = DateTime.Now;
Console.WriteLine($"{dateTime.Kind} - {dateTime}");
string ianaParis = "Europe/Paris";
string ianaHavana = "America/Havana";
var i = dateTime.ToInstant(ianaParis);
Console.WriteLine(i);
Console.WriteLine(i.ToZoned(ianaParis));
Console.WriteLine(i.ToZoned(ianaHavana));
public static class Extensions
{
public static Instant ToInstant(this DateTime dateTime, string iana)
{
if (dateTime.Kind != DateTimeKind.Local)
{
throw new ArgumentException("Expected local kind of DateTime");
}
var tz = DateTimeZoneProviders.Tzdb[iana];
global::System.Console.WriteLine(DateTimeZoneProviders.Tzdb.VersionId);
var local = dateTime.ToLocalDateTime();
ZonedDateTime z = local.InZoneStrictly(tz);
return z.ToInstant();
}
public static ZonedDateTime ToZoned(this Instant instant, string iana)
{
var tz = DateTimeZoneProviders.Tzdb[iana];
return instant.InZone(tz);
}
}ASP.NET Core provides two primary methods allowing developers to cache information; IMemoryCache and IDistributedCache. Selecting the proper caching implementation requires an understanding of your application, your future goals, and the features of both options. This post explores cache strategies.