Skip to main content

Get a File Content-Type / MIME-type from file extension in ASP.NET C#

How can I get the MIME type from a file extension in C#? This is a rather common question among developers, an evergreen requirement that I happen to heard at least once a year from friends & colleagues working with ASP.NET MVC,ASP.NET Web API and (lately) .NET Core. The reason is pretty much obvious: whenever you end up working with file object storage in any web-based or client-based application, you will sooner or later have to retrieve the MIME type related to the byte array you’re dealing with.

There are a number of ways/techniques to do that, but – for the sake of simplicity – we will put them down to two: looking them up within the Windows Registry or relying to static, hard-coded MIME type lists. We won’t consider anything that involves querying an external service, as we do want an efficient way to deal with such issue.

Read More

ASP.NET – CSS Media Queries in Razor Pages – How to embed @media syntax

If you’re working with ASP.NET MVC or ASP.NET Core using Razor pages and you want to put a CSS style within the page (CSS embed), you might stumble upon one of these following errors:

CS0103: The name ‘media’ does not exist in the current context.

CS0103: The name ‘if’ does not exist in the current context.

… And so on.

When something like that occurs, it probably means that you’re using a CSS3 media query (or other CSS3 query related commands) such as this:

Read More

Street Fighter V – Complete Move List for all Characters

A year passed from the release of Capcom’s Street Fighter V, which in my opinion  – despite all the critic and metacritic received – still holds the title of the best multiplayer fighting videogame, despite the disappointing and even detrimental arcade aspects. Although I definitely agree with most issues pointed out by the mild reviews received by the game (this from Slantmagazine being among the most complete ones), I still think that this is a great title. At the end of the story it’s (almost) all about gameplay and mechanics, and this last installment definitely comes with both.

That said, this post want to help those that still struggle with the game moves sharing this fantastic collection of Youtube training videos published by the DrewTony’Z channel. These guys really did a fantastic job and watching their work will definitely help tuning up your technique with your favourite character(s).

Let’s start with…

Read More

Midnight Cinderella – Which anime characters are the suitors inspired by?

Nearly every single fan of Midnight Cinderella has probably tried to guess which anime characters inspired the personality and the physical appearance of Cybird otome game‘s popular suitors.

We all know Cybird’s authors love to pay homage to several geek culture icons, don’t we? Actually some liknesses are explicit, others are more nuanced and finding them can be like an easter egg hunt.
After collecting several fans’ opinions about the “who looks like who” affaire, we have tried to draw up the definitive resemblances guide between Midnight Cinderella suitors and popular anime characters.
Read More

ASP.NET C# Helper Class to execute a ICMPv4 PING to any remote host using hostname or IP Address

Today I want to share this small, yet useful C# helper class that I still use when I need to retrieve, check or validate one or more IP Addresses registered on the Web Server. You can use it for a number of tasks/scenarios, including:

  • Retrieve the first available IP Address of the Web Server machine hosting the Web Application.
  • Retrieve a list of all the IPV4 and IPV6 Addresses registered on the Web Server machine hosting the Web Application.
  • Check if a given IP Address is one of the IP Addresses registered on the Web Server.

The helper class was made some years ago, yet it can still be used on any ASP.NET project, including ASP.NET Forms, ASPX pages, ASP.NET MVC, ASP.NET Web API, ASP.NET WCF with any other framework versions & builds, up to the most recent ASP.NET Core.

Here it is: enjoy!

In case you also need to retrieve IP Address(es) of the Web Server machine hosting the Web Application and/or check if a given IP Address is registered on the Web Server or not, you can integrate within this class the GetIPAddress, GetIPAddresses and HasIPAddress methods described in this other post.