在IIS服务器上将应用程序发布为xlsx文件的模仿类型后,返回应用程序/八位字节流

时间:2019-05-27 05:53:13

标签: asp.net vb.net iis mime-types

我正在尝试从文件内容中获取mime类型。在IIS Express和在Windows 10本地配置的IIS上运行良好,但是当我将应用程序发布到Windows 2012 Server时。 xlsx文件的Mime返回了application / octet-stream。

Public Shared Function GetMimeType(ByVal file As String) As String
        Dim mime As String = Nothing
        Dim MaxContent As Integer = CInt(New FileInfo(file).Length)
        If MaxContent > 4096 Then
            MaxContent = 4096
        End If

        Dim fs As New FileStream(file, FileMode.Open)

        Dim buf(MaxContent) As Byte
        fs.Read(buf, 0, MaxContent)
        fs.Close()
        Dim result As Integer = FindMimeFromData(IntPtr.Zero, file, buf, MaxContent, Nothing, 0, mime, 0)

        Return mime
    End Function

    <DllImport("urlmon.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True, 

        SetLastError:=False)>
            Private Shared Function FindMimeFromData(
                ByVal pBC As IntPtr,
                <MarshalAs(UnmanagedType.LPWStr)>
                ByVal pwzUrl As String,
                <MarshalAs(UnmanagedType.LPArray, ArraySubType:=UnmanagedType.I1, SizeParamIndex:=3)> ByVal _
                pBuffer As Byte(),
                ByVal cbSize As Integer,
                <MarshalAs(UnmanagedType.LPWStr)>
                ByVal pwzMimeProposed As String,
                ByVal dwMimeFlags As Integer,
                <MarshalAs(UnmanagedType.LPWStr)>
                ByRef ppwzMimeOut As String,
                ByVal dwReserved As Integer) As Integer
            End Function

我希望将文件xlsx输出为application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

IIS MimeType Scanpshot

0 个答案:

没有答案