ASP.NET MVC Determine mime type by file/file path

前端 未结 1 538
抹茶落季
抹茶落季 2021-02-05 16:42

I am using ASP.NET MVC 3. The application is targeting .net 4.0.

I was trying to pass a virtual path as argument to my controller\'s action and return the file without r

相关标签:
1条回答
  • 2021-02-05 17:17

    If you are using .net 4.5 there is a function now that takes a filename and returns a mimetype:

    MimeMapping.GetMimeMapping(filename)
    

    http://msdn.microsoft.com/en-us/library/system.web.mimemapping.getmimemapping.aspx

    Take a look at the function later in this question:

    How to use Generic Handlers (ASHX) in ASP.NET MVC?

    It is a little out of date with the list of file types now but it's a start, will try to find my more recent one.

    0 讨论(0)
提交回复
热议问题