我有使用EF5和MVC3数据库流小图像问题慢速图像流当一个以上的
当我流1点的画面了它的伟大工程,但是当一个页面包含像那些5它像胶水一样拍摄,它们需要长达5秒的时间才能载入事件,但每个都只有5-200kb大。
我看了一些帖子,并将此处理web.config
<system.net>
<connectionManagement>
<add address="*" maxconnection="100" />
</connectionManagement>
</system.net>
它没有对我的问题有任何影响。
并使用该流媒体:
public class ImageResult : ActionResult
{
public ImageResult(Stream imageStream, string contentType)
{
if (imageStream == null)
throw new ArgumentNullException("imageStream");
if (contentType == null)
throw new ArgumentNullException("contentType");
this.ImageStream = imageStream;
this.ContentType = contentType;
}
public Stream ImageStream { get; private set; }
public string ContentType { get; private set; }
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
throw new ArgumentNullException("context");
HttpResponseBase response = context.HttpContext.Response;
response.ContentType = this.ContentType;
byte[] buffer = new byte[4096];
while (true)
{
int read = this.ImageStream.Read(buffer, 0, buffer.Length);
if (read == 0)
break;
response.OutputStream.Write(buffer, 0, read);
}
response.End();
}
}
UPDATE
我删除了ImageResult并添加回文件......速度的东西了,但还是不能接受的速度... ..为18kb文件2秒。
控制器:
[SessionState(SessionStateBehavior.Disabled)]
public class ContentController : Controller
{
.....
public ActionResult Thumbnail(int fileID, int width)
{
var thumbnail = _fileRep.GetThumbnail(fileID, width);
return File(thumbnail.FileContent, thumbnail.ContentType);
}
添加到控制器和我的班级的ImageResult,但它仍然缓慢的胶水。 – 2013-03-26 08:40:12
@LasseEdsvik在'ActionResult'类中添加此项将不起作用,此属性仅适用于控制器。现在你正在观察的可能是暗示你有一些其他*同步点*,这会使得请求变为*“顺序”*。对于初学者,请添加控制器的源代码以及将图像提供给问题的方法。 – tpeczek 2013-03-26 08:50:48
已添加和修改代码 – 2013-03-26 09:23:41