当我想在内容文件夹中创建文件夹时,拒绝访问

时间:2021-08-04 00:28:49

hi i am using this code to upload a file with ASP.NET MVC everything is OK but it cant Access to Upload Folder :

嗨,我使用此代码上传ASP.NET MVC文件一切正常,但它无法访问上传文件夹:

public static char DirSeparator = System.IO.Path.DirectorySeparatorChar;
        public static string FilesPath = "Content" + DirSeparator + "Uploads" + DirSeparator;
        public static string UploadFile(HttpPostedFileBase file)
        {
            if (null == file) return "";
            if (!(file.ContentLength > 0)) return "";
            string fileName = file.FileName; string fileExt = Path.GetExtension(file.FileName);
            if (null == fileExt) return "";
            if (!Directory.Exists(FilesPath))
            {
                Directory.CreateDirectory(FilesPath);
            }
            string path = FilesPath + DirSeparator + fileName;
            file.SaveAs(Path.GetFullPath(path));
            return fileName;
        }

and i get this error :

我得到这个错误:

Access to '/Content/Upload/' is Denied

where is my problem,

Thanks in your Advise

我的问题在哪里,谢谢你的建议

1 个解决方案

#1


1  

Your problem is with permissions, and that your permission is being run as a user that does not have access to the location where you are requesting it to make a directory. Be sure that your user owns or has group permissions to be in, and create file/folders in the location you are trying.

您的问题在于权限,并且您的权限是以无权访问您请求其创建目录的位置的用户身份运行的。确保您的用户拥有或拥有组权限,并在您尝试的位置创建文件/文件夹。

#1


1  

Your problem is with permissions, and that your permission is being run as a user that does not have access to the location where you are requesting it to make a directory. Be sure that your user owns or has group permissions to be in, and create file/folders in the location you are trying.

您的问题在于权限,并且您的权限是以无权访问您请求其创建目录的位置的用户身份运行的。确保您的用户拥有或拥有组权限,并在您尝试的位置创建文件/文件夹。