【问题标题】:How to reliably detect mime type of uploaded [text-based] file in asp.net?如何可靠地检测 asp.net 中上传的 [基于文本的] 文件的 mime 类型?
【发布时间】:2012-01-26 06:10:26
【问题描述】:

我的网站允许上传简历,但我想确保用户不会上传除纯文本、rtf 或 word 文档(旧的 *.doc 和新的 *.docx 格式)之外的任何其他内容。显然我不能完全通过扩展来进行,我需要通过其内容以某种方式检测文件的 mime 类型。任何想法如何可靠地为上述类型做到这一点?

【问题讨论】:

    标签: c# asp.net mime-types


    【解决方案1】:

    这是 stackoverflow 上 Using .NET, how can you find the mime type of a file based on the file signature not the extension 问题的副本。这包括一个代码示例的答案,以使用 urlmon.dll 中的 FindMimeFromData 方法。

    【讨论】:

      【解决方案2】:

      上传文件时,浏览器会向您发送一个 mime 类型。虽然不是 100% 一致或可靠,但这可能是您最好的选择。

      【讨论】:

        猜你喜欢
        • 2010-09-10
        • 2011-06-03
        • 2012-04-02
        • 2012-08-10
        • 2012-09-12
        • 2012-05-17
        • 2014-02-20
        • 2011-04-13
        相关资源
        最近更新 更多