C# 文件上传到服务器

C# 文件上传到服务器,c#,sql-server-2008-r2,C#,Sql Server 2008 R2,我正在制作一个有图像上传模块的网站。在我的本地主机服务器上,它工作得非常好。这意味着我可以上传图片并保存。但是当我主持我的解决方案时,我得到了一个错误。也就是说,对路径的访问被拒绝 这是我使用的代码 string fileName = FileUpload1.FileName.ToString(); string uploadFolderPath = "~/up_foto/"; string filePath = HttpContext.Current.Server.MapPath(upload

我正在制作一个有图像上传模块的网站。在我的本地主机服务器上,它工作得非常好。这意味着我可以上传图片并保存。但是当我主持我的解决方案时,我得到了一个错误。也就是说,对路径的访问被拒绝

这是我使用的代码

string fileName = FileUpload1.FileName.ToString();
string uploadFolderPath = "~/up_foto/";
string filePath = HttpContext.Current.Server.MapPath(uploadFolderPath);
FileUpload1.SaveAs(filePath + "\\" + fileName);`
这到底是怎么回事。。请帮帮我。。。。
提前感谢….

如果您的代码在本地运行,恐怕代码没有问题。相反,您必须确保在主机环境中,用户“IUSER”或“IIS_IUSER”等是否具有对上载文件夹的访问权限(读/写)。

由于您获得了“路径访问被拒绝”,您是否检查了您尝试上载的文件夹是否具有写访问权限?

您可以使用path.combine或server.mappath(别忘了在名称空间中添加System.IO)


1.)使用路径。合并(而不是将字符串添加在一起,2。)发生故障的目标服务器上是否存在
~/up\u foto/
文件夹?同时检查
~/up\u foto/
文件夹是否具有读/写权限。如何检查该文件夹是否具有读/写权限?@user3159647如果您有一个用于托管网站的控制面板,则会有一个文件夹权限部分供您使用。或者,如果您有FTP帐户并使用Filezilla上载文件,您可以右键单击要上载的文件夹,并授予所需的权限。
        string fileName = FileUpload1.FileName.ToString();
        string uploadFolderPath = "~/Uploads/Images/";
        string filePath1 = Server.MapPath(uploadFolderPath + fileName);
        string fileName = FileUpload1.FileName.ToString();
        string uploadFolderPath = "~/Uploads/Images/";
        string filePath = Server.MapPath(uploadFolderPath);
        string filePath1= Path.Combine(filepath1 + fileName);