Getting Mime types and file extensions from registry using C#

If you have a mime type and you want to find the default extension for this mime type, you can get this from the following registry key
HKEY_CLASSES_ROOT\MIME\Database\Content Type\<mime type>

public static string GetDefaultExtension(string mimeType)
{
  string result;
  RegistryKey key;
  object value;
  key = Registry.ClassesRoot.OpenSubKey("MIME\Database\Content Type\" + mimeType, false);
  value = key != null ? key.GetValue("Extension", null) : null;
  result = value != null ? value.ToString() : string.Empty;
  return result;
}

on the other hand, if you have the file extension and you want the mime type of this extension
HKEY_CLASSES ROOT\<extension>

public static string GetMimeTypeFromExtension(string extension)
{
  string result;
  RegistryKey key;
  object value;
  if (!extension.StartsWith("."))
    extension = "." + extension;
  key = Registry.ClassesRoot.OpenSubKey(extension, false);
  value = key != null ? key.GetValue("Content Type", null) : null;
  result = value != null ? value.ToString() : string.Empty;
  return result;
}

and this is all :) 

filter attribute that checks whether current connection is secured

using APS.net Core to mark all website pages working with https protocol we will do this using IAuthorizationFilter. and here is an exampl...