Part 2 of a Roslyn analyzer series builds UseElmahIoOrderAnalyzer.cs (diagnostic ID EIO1002), scanning the Configure method of a Startup class to warn when UseElmahIo middleware is registered before UseDeveloperExceptionPage or UseExceptionHandler, using RegisterCodeBlockStartAction. ...
A free alternative to paid PDF components like NReco.PdfGenerator: install Wkhtmltopdf.NetCore, wire it up with AddWkhtmltopdf in ConfigureServices, place the wkhtmltopdf executable in a wkhtmltopdf/Windows folder, then inject IGeneratePdf into a controller to render a Razor view to PDF. ...
Part 1 of a Roslyn analyzer series: from Visual Studio's Analyzer with Code Fix template, builds CallUseElmahIoAnalyzer.cs (diagnostic ID EIO1001) using RegisterCodeBlockStartAction to flag a Startup.Configure method that never calls UseElmahIo, citing Andrew Lock on middleware ordering. ...
Compares C#/.NET email-sending options in code: the built-in System.Net.Mail SmtpClient and MailMessage classes over SMTP port 587, generating a Google Workspace App password for Gmail SMTP, plus AWS Simple Email Service, Mandrill, and Azure as alternatives to hosting your own SMTP server. ...
Compares three ways to convert a string to int in C#: int.Parse (throws FormatException on bad input), int.TryParse (returns a bool with no exception needed, the recommended approach), and Convert.ToInt32, whose char overload silently converts the character 1 to its UTF code 49, not the number 1. ...
Walks through fixing an Azure DevOps pipeline that fails to build a self-contained .NET 5 console app for win-x64: adding a RuntimeIdentifiers element to fix NETSDK1047, then resolving a 401 from a custom NuGet feed by adding --no-restore to dotnet build and --no-build to dotnet publish. ...
Builds a minimal RequestLoggingMiddleware for ASP.NET Core that logs one structured message per request (method, URL, status code) via Microsoft.Extensions.Logging, wired up with app.UseMiddleware, and paired with Elmah.Io.AspNetCore.ExtensionsLogging to attach HTTP context to each entry. ...
Covers three layered approaches to catching errors in a C# Windows Forms app: try/catch blocks, the Application.ThreadException event for unhandled UI-thread exceptions, and a GlobalExceptionHandler wired to AppDomain.CurrentDomain.UnhandledException, logging to a file or Serilog, NLog, elmah.io. ...
Fourth in an ASP.NET security series: shows how to stop XSS from hijacking the .ASPXAUTH authentication cookie by setting requireSSL and httpOnlyCookies in web.config httpCookies element (or Secure/HttpOnly on an HttpCookie in C#), plus disabling TRACE requests to prevent Cross-Site Tracing. ...