How To

How to use NetEscapades.​AspNetCore.​SecurityHeaders
By Tan Lee Published on Jan 03, 2025 899

NetEscapades.AspNetCore.SecurityHeaders is a .NET library that helps you easily set HTTP security headers in ASP.NET Core applications to improve security by protecting against various types of attacks (like XSS, clickjacking, etc.).

How to setup a webapi controller for multipart/form-data
By Tan Lee Published on Feb 16, 2024 1.07K

If you uploaded file through webapi in angularjs and encountered the following error: ExceptionMessage=No MediaTypeFormatter is available to read an object of type ‘HttpPostedFileBase’ from content with media type 'multipart/form-data'.

Sorting a SortedList in Descending Order in C#
By Tan Lee Published on Feb 07, 2025 328

In C#, the SortedList<TKey, TValue> class stores key-value pairs in ascending order of the key by default. If you need to store the elements in descending order, you can achieve this by using a custom comparer.

Difference between delegate and event in C#
By Tan Lee Published on Feb 07, 2025 406

In C#, both delegates and events are essential constructs for handling method references and providing a way to notify subscribers when something happens.

How to calculate code execution time in C#
By Tan Lee Published on Feb 07, 2025 542

To calculate the code execution time in C#, you can use the Stopwatch class from the System.Diagnostics namespace.

How to Read a File Using StreamReader in C#
By Tan Lee Published on Feb 07, 2025 421

To read a file in C#, you can use the StreamReader class. It simplifies reading text from a file by providing various methods for reading data.

Difference Between Hashtable and Dictionary in C#
By Tan Lee Published on Feb 07, 2025 362

In C#, both Hashtables and Dictionaries are popular collections used for storing and retrieving key-value pairs.

Difference between Array and ArrayList in C#
By Tan Lee Published on Feb 07, 2025 281

In C#, both Array and ArrayList are used to store collections of elements.

Writing Text to a Physical File Using StreamWriter in C#
By Tan Lee Published on Feb 07, 2025 276

To write text to a physical file using StreamWriter in C#, you can follow these steps.

Difference between string and StringBuilder in C#
By Tan Lee Published on Feb 07, 2025 335

In C#, both string and StringBuilder are used to work with text, but they differ significantly in how they handle memory and performance when modifying text.

DateTime formats in C#
By Tan Lee Published on Feb 07, 2025 300

In C#, you can convert a `DateTime` object to a string in various formats using the `ToString()` method. By passing the desired format as a string parameter to the `ToString()` method, you can retrieve the date and time in the required format.

How to get unix timestamp in C#
By Tan Lee Published on Jul 11, 2024 2.63K

In C#, you can get the Unix timestamp, which represents the number of seconds that have elapsed since January 1, 1970 (Unix epoch), in a couple of ways.