I’m having an image file named SampleData with extension as .shweta. Here shweta is my custom extension andthe browser has no information about it. The browser has no idea about how to render this type of file. Please note, this is a static resource placed on wwwroot and has to be served to client. Now quickly open SampleData.shweta in browser and see what happens.


Uhh! This is HTTP 404 Not Found :( .
Now the question is why is there such a discrepancy? Straight forward answer would be – ASP.NET middleware is not able to serve this unknown file type.
Serving unknown content type
In order to serve files of an unknown type, we have to tell the browser which type of file is this. Fortunately, ASP.NET provides us with two useful properties named ServeUnknownFileTypes and DefaultContentType which will do this task for us.
Now if the user glances at a file whose content type is unknown, the browser will treat it as an image and render it accordingly as shown below:
The next interesting question is, what if there are multiple types of files having an unknown to ASP.NET? No worries, ASP.NET Core has solution for that also.
Serving multiple unknown content types
It provides a class named FileExtensionContentTypeProvider. Hence any custom content type has to be first added in a collection of this class with proper mapping of extension MIME type. Below is the sample code for achieving this:
More information about FileExtensionContentTypeProvider class is given here at github and more information about application/x-msdownload is given here.





Asfend YarPosted Feb 29, 2016, 1:40 PM
good
Pramod ThakurPosted Feb 5, 2016, 2:44 AM
Nice..
Ajeet MishraPosted Feb 5, 2016, 2:10 AM
nice
Raja TPosted Feb 4, 2016, 10:49 PM
Nice,Thanks for sharing
Vivek KumarPosted Feb 4, 2016, 2:35 PM
Nice article
Mohammed IbrahimPosted Feb 4, 2016, 1:47 PM
nice
Debasis SahaPosted Feb 4, 2016, 9:54 AM
Nice Share..
Vaikesh K PPosted Feb 4, 2016, 7:55 AM
Nice one
Sibeesh VenuPosted Feb 4, 2016, 12:46 AM
Nice Share
Santhakumar MunuswamyPosted Feb 3, 2016, 3:06 PM
Thanks for nice share
Ankit SaxenaPosted Feb 3, 2016, 11:09 AM
Very nice explanation.
Nanddeep NachanPosted Feb 3, 2016, 1:14 AM
Nice share
Amit Kumar SinghPosted Feb 3, 2016, 12:57 AM
Nice
Saineshwar BageriPosted Feb 3, 2016, 12:33 AM
Nice one
Shubham KumarPosted Feb 3, 2016, 12:28 AM
nice
Sibeesh VenuPosted Feb 3, 2016, 12:28 AM
Nice Share
Debasis SahaPosted Feb 2, 2016, 11:44 PM
Nice one..
Pramod ThakurPosted Feb 2, 2016, 9:17 PM
thanx for sharing..
Mohammed IbrahimPosted Feb 2, 2016, 2:14 PM
nice