简体   繁体   English

文件上传到服务器

[英]File uploading into server

I am making a website having image upload module.In my localhost server its working perfectly. 我正在制作一个具有图像上传模块的网站。在我的本地主机服务器中,它运行正常。 That means i can upload images and save it. 这意味着我可以上传图像并保存。 But when i host my solution i am getting a error. 但是,当我托管我的解决方案时,我得到了一个错误。 That is, Access to the path is denied. 即,拒绝访问路径。

This is the code i have used... 这是我使用的代码...

string fileName = FileUpload1.FileName.ToString();
string uploadFolderPath = "~/up_foto/";
string filePath = HttpContext.Current.Server.MapPath(uploadFolderPath);
FileUpload1.SaveAs(filePath + "\\" + fileName);`

What the wrong in this.. Please help me.... Thanks in advance.... 这是怎么了..请帮助我....在此先谢谢....

I am afraid there's nothing wrong with your code, if it runs locally. 如果代码在本地运行,恐怕代码没有问题。 Instead, you have to make sure if on the host environment the user "IUSER", or "IIS_IUSER", or the like, has access (Read/Write) to the upload folder. 相反,您必须确保在主机环境上,用户“ IUSER”或“ IIS_IUSER”等是否具有对上载文件夹的访问权限(读取/写入)。

由于您收到“拒绝访问路径”的信息,是否检查了要上传的文件夹是否具有写权限

you can use Path.combine or server.mappath (dont forget to add System.IO in the namespaces) 您可以使用Path.combine或server.mappath(不要忘记在名称空间中添加System.IO)

        string fileName = FileUpload1.FileName.ToString();
        string uploadFolderPath = "~/Uploads/Images/";
        string filePath1 = Server.MapPath(uploadFolderPath + fileName);

or 要么

        string fileName = FileUpload1.FileName.ToString();
        string uploadFolderPath = "~/Uploads/Images/";
        string filePath = Server.MapPath(uploadFolderPath);
        string filePath1= Path.Combine(filepath1 + fileName);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM