에 파일을 업로드 할 수없는 내가 내 로컬 호스트에서 작업을 수행 할 때 잘 작동하지만 난 그것을 게시 할 때 서버에서 오류가 발생 :서버
이 코드를 사용하는 경우 :
public string ImagePath(HttpPostedFileBase imgfile)
{
var path = "";
// code for saving the image file to a physical location.
var fileName = Path.GetFileName(imgfile.FileName);
path = Path.Combine(HttpContext.Server.MapPath("~/Images/Sections/Developer/ClientLogo"), fileName);
string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(imgfile.FileName);
int iteration = 1;
while (System.IO.File.Exists((path)))
{
fileName = string.Concat(fileNameWithoutExtension, "-", iteration, System.IO.Path.GetExtension(imgfile.FileName));
path = Path.Combine(HttpContext.Server.MapPath("~/Images/Sections/Developer/ClientLogo"), fileName);
iteration++;
}
imgfile.SaveAs(path);
// prepare a relative path to be stored in the database and used to display later on.
path = Url.Content(Path.Combine("~/Images/Sections/Developer/ClientLogo", fileName));
return path;
}
오류
System.UnauthorizedAccessException입니다 : 경로 'D 액세스 : \을 Inetpub \ 가상 호스트 \ xx.com \ httpdocs \ 이미지 \ 섹션 \ 개발자 \ ClientLogo \ 원 - 작은 빈. 18x18.png '이 거부되었습니다. System.IO .__ Error.WinIOError System.IO.FileStream.Init에서 (INT32의 errorCode, 문자열 maybeFullPath) (문자열 경로, 대한 fileMode 모드, FileAccess 액세스, INT32 권한, 부울 useRights, 파일 공유 점유율, INT32 BUFFERSIZE, FileOptions 옵션에서 secAttrs을 SECURITY_ATTRIBUTES System.IO.FileStream.ctor (String 경로, FileMode 모드, FileAccess 액세스, FileShare 공유, Int32 bufferSize, FileOptions 옵션, String msgPath, 부울 bFromProxy)에서 System.IO.FileStream.ctor (String msgPath, 부울 bFromProxy, 부울 bFromProxy, 부울 useHongPath). xx.CorporateSite.Controllers.DeveloperController.ImagePath에서 System.Web.HttpPostedFileWrapper.SaveAs에서 System.Web.HttpPostedFile.SaveAs에서 IO.FileStream..ctor (문자열 경로, 대한 fileMode 모드) (문자열 파일 이름) (문자열 파일 이름) (HttpPostedFileBase imgfile)
And when I use Server.MapPath instead of HttpContext.Server.MapPath it throw different error:
오류 :
System.IO.DirectoryNotFoundException : 'D : \ InetPub \ vhosts \ xx.com \ httpdocs \ Images \ Sections \ Developer \ ClientLogo \ demo.png'경로의 일부를 찾을 수 없습니다. System.IO .__ Error.WinIOError System.IO.FileStream.Init에서 (INT32의 errorCode, 문자열 maybeFullPath) (문자열 경로, 대한 fileMode 모드, FileAccess 액세스, INT32 권한, 부울 useRights, 파일 공유 점유율, INT32 BUFFERSIZE, FileOptions 옵션에서 secAttrs을 SECURITY_ATTRIBUTES System.IO.FileStream.ctor (String 경로, FileMode 모드, FileAccess 액세스, FileShare 공유, Int32 bufferSize, FileOptions 옵션, String msgPath, 부울 bFromProxy)에서 System.IO.FileStream.ctor (String msgPath, 부울 bFromProxy, 부울 bFromProxy, 부울 useHongPath). xx.CorporateSite.Controllers.DeveloperController.ImagePath에서 System.Web.HttpPostedFileWrapper.SaveAs에서 System.Web.HttpPostedFile.SaveAs에서 IO.FileStream..ctor (문자열 경로, 대한 fileMode 모드) (문자열 파일 이름) (문자열 파일 이름) (HttpPostedFileBase imgfile)
내 로컬 호스트에서 권한을 변경하려고했지만 아무 것도 작동하지 않습니다 ... 제발 제안하십시오
'appSetting'은 문자열 값이기 때문에 필요한 경우 '~ \ Images \ ...'와 같은 상대 경로를 사용할 수 있습니다. 그러나 핵심은 web.config에 유지하여 하드 코딩되지 않도록하는 것입니다. 귀하의 환경이 확실하지 않지만 관리자가있는 경우 이미지 저장 위치 (예 : NAS 또는 다른 유형의 저장 장치)를 결정할 가능성이 있으며 해당 위치에서 적절한 권한 설정을 담당하게됩니다 서버. –
내가 u 설정을 사용할 때. 오류가 발생 함 : System.Web.HttpException (0x80004005) : SaveAs 메서드가 루트 경로와 'abc.com/images/sections/Developer/ClientLogo/'경로를 요구하도록 구성되었습니다. over.png '; 뿌리가 없다 – user207888