Use the ExceptionDispatchInfo Class to Capture the Entire Exception

The ExceptionDispatchInfo class can be found in System.Runtime.ExceptionServices namespace and is used to capture an exception that occurs at a point, and it can be thrown later using the ExceotionDispatchInfo.Throw method. See below for an example. ExceptionDispatchInfo exceptionDispatchInfo = null; try { //code that throws error } catch (Exception ex)

Switch to HTTP2 for Faster Websites

HTTP2 is binary protocol released some time after 2015. It is completely multiplexed and allows you to send multiple requests via a single TCP connection. It also reduces additional round trip time to the server. IIS 10.0 and above supports HTTP2 natively.

Add Support for Custom Media in ASP.NET Web APIs

ASP.NET’s Web APIs support custom formatters. One of the best examples for a custom media formatter is a Vcalendar data format that can used in calendar software such as Outlook. After you build the custom media formatter, all of you have to do is add it to the Web API

Identify Troublesome Web Queries in IIS

The IIS admin interface lets you view the worker process details that are sometimes helpful to debug server performance issues. Choose the “Worker Processes” in the list of options in the IIS interface. Click on the worker processes. You will see all the current requests that are executing in the

Using Swagger to Document Your ASP.NET Web APIs

Web APIs are pretty useful to share data. One of the most common problems faced while consuming APIs is the lack of documentation and testable features. Swagger bridges that gap by providing interactive documentation and dynamic test interfaces. There are many articles on how to integrate Swagger on top of

Faster Way to Attach a Process During Debugging

In Visual Studio 2017, the “attach to process” window has an option that allows you to search and filter for a process. It is a search text box right on top of the “available process” section. No more scrolling through the mammoth list of processes running on your machine or

How to Restrict Input Text to Characters in a Text Box

Use the KeyPress event to check for the keys pressed. See below for an example: private void textFirstName_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if ( !( char.IsLetter(e.KeyChar) ) ) { e.Handled = true; } }

Check Whether a String Contains Another String

Often, we have to do a string comparison by ignoring the case, or the results end up being wrong. The StringComparison enum provides the “ordinalignorecase” member that allows you to do this. See below for an example. string searchString = “John”; string completeString = “johnDoe”;bool exists = completeString.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) =

How to Escape Curly Braces in C#

To escape curly braces in c#, use double curly braces. See the example below. var stringWithCurlyBraces = string.Format(“Good {{ ???{0}??? }}”,”example”);Console.Write(stringWithCurlyBraces);//will output Good { ‘example’ }

No more posts to show