Posts

Showing posts from May, 2025

๐Ÿ”Œ Extension Methods in C#: Power Up Your Code Without Modifying It

Have you ever wanted to add a method to an existing class (like string, DateTime, or even your own types) — without changing its source code? That’s exactly what extension methods in C# are for. ๐Ÿš€ What Is an Extension Method? An extension method lets you "extend" an existing type (class or struct) with new methods , without modifying the type itself . ✅ It feels like you're adding a method to the type ✅ But you're really writing a static method with a special syntax ๐Ÿงช Real-Life Example Let’s say you want to capitalize the first letter of a string: ❌ Without Extension: csharp public static class StringUtils {     public static string Capitalize(string value)     {         if (string.IsNullOrEmpty(value)) return value;         return char.ToUpper(value[0]) + value.Substring(1);     } } Usage: csharp string name = "...

๐Ÿ›ก️ SIEM Logs Explained: How to Build Secure and Auditable .NET Apps

  In today’s security-conscious world, it’s no longer enough to just log errors and crashes. You need to log security-related events too — for compliance , auditing , and incident response . That’s where SIEM logs come in. ๐Ÿง  What is SIEM? SIEM (Security Information and Event Management) is a security solution that helps organizations collect, store, analyze, and alert on security-related logs and events. Popular SIEM platforms include: ๐Ÿ›ก️ Splunk ๐Ÿ“Š IBM QRadar ☁️ Microsoft Sentinel ๐Ÿงญ Elastic SIEM ๐Ÿ” ArcSight ๐Ÿ“ฆ What Are SIEM Logs? SIEM logs are not a specific format. They’re structured logs that contain security-relevant events , such as: User logins / logouts Failed login attempts Access to sensitive data Privilege escalation System configuration changes These logs are sent from apps and servers to a central SIEM system , where they are: Parsed Correlated Stored Alerted upon ๐Ÿงฑ Anatomy of a Good...

๐ŸŒ CORS in .NET Explained: Solving the Cross-Origin Problem Like a Pro

  Have you ever seen this error? Access to fetch at 'http://api.example.com/data' from origin 'http://localhost:4200' has been blocked by CORS policy ๐Ÿ˜– Frustrating, right? Don’t worry — it’s a CORS issue , and in this post, we’ll break it down and solve it . ๐Ÿง  What is CORS? CORS (Cross-Origin Resource Sharing) is a browser security feature that controls how web pages can make requests to a different domain than the one that served the web page. ๐Ÿ”’ Same-Origin Policy Browsers follow the Same-Origin Policy , which means: A frontend running on http://localhost:3000 Cannot make API calls to http://api.mysite.com (a different origin) Unless the server allows it via CORS headers ๐Ÿงพ CORS in Real Life Imagine your Angular app runs at: http://localhost:4200 And your .NET Core Web API runs at: http://localhost:5000 By default, if you try to call the API from the frontend, the browser will block the request unless...

๐Ÿ” JWT (JSON Web Token) Explained: Secure Your APIs the Modern Way

  If you're building APIs or modern web apps, you've probably heard of JWT . But what is it, really? In this post, we'll break down: What JWT is How it works Why and when to use it How to implement it in a .NET Core API ๐Ÿš€ What is JWT? JWT stands for JSON Web Token . It’s a compact, URL-safe token used to securely transmit information between two parties — typically between a client and a server. Unlike traditional session-based authentication (which stores session data on the server), JWT is stateless . All the information is stored in the token itself . ๐Ÿงฑ Structure of a JWT A JWT has three parts , separated by dots: xxxxx.yyyyy.zzzzz 1. Header Specifies the type of token and the algorithm used to sign it. json {   "alg": "HS256",   "typ": "JWT" } 2. Payload Contains the claims (data like user ID, roles, expiration, etc.). json {   "sub": "1234567...