【发布时间】:2015-10-13 19:07:18
【问题描述】:
我正在使用在页面中呈现多媒体内容的处理程序。
这个想法是这个处理程序访问文件并使用扩展名确定类型,并呈现它,问题是大多数时候处理程序本身被下载 并且没有显示多媒体。
代码如下:
FileInfo file = new FileInfo(filePath);
byte[] bytes = new byte[file.Length];
using (FileStream fs = file.OpenRead())
{
fs.Read(bytes, 0, bytes.Length);
}
string extension = Path.GetExtension(filePath);
string mimeDeclaration;
if (".tif" == extension)
mimeDeclaration = "tiff";
string[] imagenes = new string[] {".jpg", ".jpeg", ".bmp", ".gif", ".png"};
if (imagenes.Any(x => x.Contains(extension)))
mimeDeclaration = extension.Substring(1);
else
mimeDeclaration = string.Empty;
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "image/" + mimeDeclaration;
context.Response.BinaryWrite(bytes);
filePath 变量有效。
您能帮我避免处理程序不呈现多媒体内容吗?
【问题讨论】:
-
什么是“意外动作”?
-
问题是什么?
-
问题是handler.cs被下载了
-
检查
filePath也许是错误的文件。 -
@Bauss 不幸的是,情况并非如此:(
标签: c# handler mime-types mime