How to get ContentType for file in ASP.NET MVC when using File Action Method

我的未来我决定 提交于 2019-12-02 12:20:34

问题


Attempting to use asp.net mvc's Action Result of File.

So it would seem that I have to specify a ContentType for the file to be sent to the browser. Currently there is no real limit to what types of files may be sent to the browser in my application, so I can't always assume it will be a "text/pdf", for example.

What's the best way of working out the ContentType of a file, or is there a way where this can be set to something 'generic'?

The simpler the better!

Thanks,


回答1:


You either user the local machine's database of MIME types (from the registery):

http://www.codeproject.com/KB/dotnet/ContentType.aspx

or find an alternate dictionary. Like this duplicate SO question.



来源:https://stackoverflow.com/questions/1594787/how-to-get-contenttype-for-file-in-asp-net-mvc-when-using-file-action-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!