I am trying to determine the Mime Type of an uploaded file using C#. There are various methods to get the MIME type from the file extension (ContentType for the HttpPosted File, GetMimeMapping from the filename, etc). However all of these methods rely on the file name/extension.
This would allow a user to upload an unwanted file (like an .exe), by simply changing the extension of the file to an accepted extension (like .png). Since these methods determine the file type based on the extension, the exe would be passed off as a png image file.
I would like to be able to check the data in the file headers in order to determine the file type, instead of relying on filename. Are there are libraries or utilities which can help determine the file type by looking at the data/header instead of filenames and extensions?