我正在尝试将图像文件上传到服务器,但出现错误
"System.UnauthorizedAccessException: Access to the path 'D:\Hosting\234344\html\Testingfiles\upload\813.jpg' is denied.at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)"
在我的 HttpHandler 中:
HttpPostedFile file = context.Request.Files["Filedata"];
string usr_id = context.Request.Form["usr_id"];// gets the JSON data from the request
string strPath = context.Server.MapPath(("/Testingfiles/upload/") + file.FileName);
string ext = Path.GetExtension(strPath);
if (ext.Equals(".jpg") || ext.Equals(".jpeg") || ext.Equals(".png"))
{
file.SaveAs(strPath);
context.Response.Write("Image uploaded successfully");
}
我做错了什么?
最佳答案
错误消息说明了一切。您没有对该文件夹的写入权限。
您需要请求您的托管服务提供商为 ASP .NET 身份分配对该文件夹的写入权限。
此外,请考虑是否可以使用 ~/App_Data
下的文件夹。按照惯例,这是在 ASP .NET 中存储需要写入访问权限的文件的地方,因此许多托管服务提供商将默认允许写入此文件夹(但您需要自行检查您的特定主机以确定)。
关于c# - 如何访问共享主机空间上的文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8776806/