Member-only story

C# Extension Methods that come in handy for an ASP.Net Project

Venky Writes
4 min readFeb 4, 2024

In the realm of C# and ASP.NET development, extension methods serve as invaluable tools, empowering developers to enhance the expressiveness and efficiency of their code. In this blog post, we will delve into some of the basic extension methods that any ASP.Net Core project needs and can elevate your web development projects.

HTTPContext Extensions

Get Base Path


public static string GetBasePath(this HttpContext httpContext)
{
return $"{httpContext.Request.Scheme}://{httpContext.Request.Host}";
}

Check if the Request Header has a particular key

public static bool HasRequestHeader(this HttpContext httpContext, string headerName)
{
return httpContext.Request.Headers.ContainsKey(headerName);
}

Check if the Response Header has a particular key

public static bool HasResponseHeader(this HttpContext httpContext, string headerName)
{
return httpContext.Response.Headers.ContainsKey(headerName);
}

Check if the Request Header key has the required value

public static bool HasRequestHeaderValue(this HttpContext httpContext…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Written by Venky Writes

Web Architect .Net Core, API, Azure, Serverless, Product Design & Delivery, Agile, C#, MVC, SQL DB, Cosmos DB, DevOps, Azure Log Analytics and Workspaces (KQL)

Responses (6)

What are your thoughts?