3

写真を表示するページがいくつかあります。コードが[投稿のアート]に示されているコントローラーアクションを呼び出します。問題は、シュレッディングから読み込まれた画像であり、すぐに読み込まれるのではなく、最初にテキストを表示してから画像を表示することです。さらに2つ試しました画像をロードするための正確な方法ですが、同じ効果... 1つずつロードしてください。現在のコードアクションを助けてください

    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. 画像のキャッシングをロードした後、すぐに開発者の皆さんを助けてください

パート 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 の Web サーバーに組み込まれている) では機能しません。これは一度に 1 つの要求しか処理しないためですが、IIS Express または IIS でテストすると、最初の方法を使用してそれらが並行して読み込まれることがわかります。

于 2012-09-06T09:16:30.017 に答える