Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 会话存储临时和检索图像并存储到模型中_C#_Asp.net Mvc_Image_Session Variables_Temporary Files - Fatal编程技术网

C# 会话存储临时和检索图像并存储到模型中

C# 会话存储临时和检索图像并存储到模型中,c#,asp.net-mvc,image,session-variables,temporary-files,C#,Asp.net Mvc,Image,Session Variables,Temporary Files,我一直在寻找解决asp文件上传限制的方法,但在我的问题中,仍然没有人回答。现在,我能知道这里是否有人知道如何使用会话存储临时图像,然后将其检索回流并将其放入模型?您可以将图像转换为字节数组,然后将其转换为base64字符串并保存到会话中。然后将其转换为字节数组,并将其绑定到控件。我终于找到了解决方案 示例现在我有一个文件在model.file中,类型是httppostedfilebase,我应该如何将其转换为字节数组?或者它可以直接存储在会话中?一旦你有了字节数组,你就可以;string str

我一直在寻找解决asp文件上传限制的方法,但在我的问题中,仍然没有人回答。现在,我能知道这里是否有人知道如何使用会话存储临时图像,然后将其检索回流并将其放入模型

您可以将图像转换为字节数组,然后将其转换为base64字符串并保存到会话中。然后将其转换为字节数组,并将其绑定到控件。

我终于找到了解决方案


示例现在我有一个文件在model.file中,类型是httppostedfilebase,我应该如何将其转换为字节数组?或者它可以直接存储在会话中?一旦你有了字节数组,你就可以;string str=convert.toBase64String(bytearr);我们谈论的是存储还是检索?对不起,aski认为我们讨论的是存储,对吗?我已经做了,检索是什么?顺便说一下,izzit correct?MemoryStream target=新的MemoryStream();model.File.InputStream.CopyTo(目标);字节[]数据=target.ToArray();字符串位置=Convert.tobase64字符串(数据);会话[“文件1”]=地点;
        if (model.File != null && model.File.ContentLength > 0)
        {
            Byte[] destination1 = new Byte[model.File.ContentLength];
            model.File.InputStream.Position = 0;
            model.File.InputStream.Read(destination1, 0, model.File.ContentLength);
            model.BankSlip = destination1;
            Session["info.file"]= model.File;//storing session.
        }
        else
        {
            //retrieving session
            var myImg1 = Session["info.file"] as HttpPostedFileBase;
            model.File = myImg1;
            Byte[] data=new Byte[myImg1.ContentLength];
            myImg1.InputStream.Position = 0;
            myImg1.InputStream.Read(data, 0, myImg1.ContentLength);
            model.BankSlip = data;
        }
        }
        catch (Exception ex)
        {                   
            DepositControllerLog.ErrorException("DepositController - LocalBank(Post) - AddAttachment(refreshed) - ", ex);
        }
        }