ASP.NET图像上传问题 [英] ASP.NET Image Upload Problem

查看:84
本文介绍了ASP.NET图像上传问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我在ASP.NET中的C#代码,用于将图像上传到FTP。我的问题是:



Below is my C# code in ASP.NET to upload images in to the FTP. My problems is:

protected void UploadButton_Click(object sender, EventArgs e)
{
 if (FileUploadControl.HasFile)
            {
                try
                {
                    if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
                    {
                        if (FileUploadControl.PostedFile.ContentLength < 5242881)
                        {
                            string filename = Path.GetFileName(FileUploadControl.FileName);
                                                    
                            Stream image;
                                string target = "1.jpg";
 
                                FtpWebRequest req = (FtpWebRequest)WebRequest.Create("ftp://ftppath" + target);
                                req.UseBinary = true;
                                req.Method = WebRequestMethods.Ftp.UploadFile;
                                req.Credentials = new NetworkCredential("ftpUname", "ftpPass");
 
                                byte[] fileData = File.ReadAllBytes(filename);
 
                                req.ContentLength = fileData.Length;
                                Stream reqStream = req.GetRequestStream();
                                reqStream.Write(fileData, 0, fileData.Length);
                                reqStream.Close();                            
                             
                             StatusLabel.Text = "Upload status: File uploaded!";
                        }
                        else
                            StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";
                    }
                    else
                        StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
}



在我完全拥有特定文件夹的同时,始终收到以下错误。



'System.Net.WebPermission,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'失败。



请帮帮我。


Always getting following error while I have given full right to the particular folder.

'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Please help me.

推荐答案

参考

http://stackoverflow.com/ question / 15237902 / how-to-request-a-permission-type-system-net-webpermission-in-asp-net-mvc [ ^ ]

http:// blogs .iis.net / hosterposter / archive / 2006/03/22 / Enabling-WebPermission-in-Medium-Trust.aspx [ ^ ]


这篇关于ASP.NET图像上传问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆