3

我有几个显示图片的页面,它们调用控制器动作,其代码显示在[post的艺术加载图像的精确方法但效果相同......所以一一加载,请为您提供帮助当前代码操作

    public FileContentResult ImageVew(string sourcePath)
    {

        string location = (string)Session["TicketFilePath"] + sourcePath;



        byte[] myByte = System.IO.File.ReadAllBytes(location);

        return File(myByte, "image/jpeg");


        Image i;
        using (MemoryStream ms = new MemoryStream())
        {
            ms.Write(myByte, 0, myByte.Length);
            i = Image.FromStream(ms);
        }
        return File(imageToByteArray(i.GetThumbnailImage(100, 100, () => false, IntPtr.Zero)), "image/png");
    }

    public byte[] imageToByteArray(System.Drawing.Image imageIn)
    {
        MemoryStream ms = new MemoryStream();
        imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        return ms.ToArray();
    }

最新版本此方法,但不是结果

    public ActionResult ImageVew(string sourcePath)
    {
        FileInfo fi = new FileInfo((string)Session["TicketFilePath"] + sourcePath);

        return File(fi.FullName, Utilities.MimeType(fi.Name));
    }

    public ActionResult ImageVew(string sourcePath)
    {
        FileInfo fi = new FileInfo((string)Session["TicketFilePath"] + sourcePath);

        byte[] imageFile = System.IO.File.ReadAllBytes(fi.FullName);
        return new FileContentResult(imageFile, Utilities.ImageType(fi.Name));


    }

    public ActionResult ImageVew(string sourcePath)
    {

        FileInfo fi = new FileInfo((string)Session["TicketFilePath"] + sourcePath);
        if (fi.Exists)
        {
            byte[] imageFile = System.IO.File.ReadAllBytes(fi.FullName);

            return File(imageFile, Utilities.ImageType(fi.Name));
        }
        else return null;
    }

图像渲染 1 比 1 并从网络路径加载图像......但在 1. 加载图像兑现之后,以及小伙子时刻请帮助我开发人员

f 部分代码然后调用带有渲染 m 控制的操作

 private void WriteDataRow(Class item, HtmlTextWriter writer) 
    {
 writer.RenderBeginTag(HtmlTextWriterTag.Td);
        writer.RenderBeginTag(HtmlTextWriterTag.Center);
        writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "20px");
        string src = Url.Action("ImageVew", new { sourcePath = item.Status.Marker });
        writer.AddAttribute(HtmlTextWriterAttribute.Src, src );
        writer.AddAttribute(HtmlTextWriterAttribute.Alt, item.Status.StatusName);
        writer.RenderBeginTag(HtmlTextWriterTag.Img);
        writer.RenderEndTag();
        writer.RenderEndTag();
        writer.RenderEndTag();
}
4

1 回答 1

2

Asp.net mvc 永远不会同时处理来自同一用户(实际上是同一会话)的多个请求,除非您打开会话状态或使其只读该操作。

到控制器或您需要添加的操作

[SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]

现在这不适用于 Cassini(Visual Studio 中内置的网络服务器),因为它一次只提供一个请求,但是如果您使用 IIS express 或 IIS 进行测试,您应该会看到它们使用第一种方法并行加载。

于 2012-09-06T09:16:30.017 回答