2013-01-12 3 views
0

로컬 컴퓨터에서 아래 코드는 제대로 작동하지만 원격 서버에서 호스팅 할 때 이미지 파일을 찾지 못하는 것 같습니다. Image 폴더를 생성하고 읽기/쓰기 권한도 부여했습니다.ASP.NET MVC 3.0에서 이미지를 업로드 할 때 오류가 발생했습니다.

// ------------------------------ --------------
오류

Server Error in '/' Application. 
Could not find file 'IdImage.jpg'. 

설명 : 처리되지 않은 예외가 현재 웹 요청을 실행하는 동안 일어났다. 오류 및 코드에서 시작된 위치에 대한 자세한 정보는 스택 추적을 검토하십시오.

Exception Details: System.IO.FileNotFoundException: Could not find file 'IdImage.jpg'.

코드 ---------------------------------
// 다음과 같다 ------------

[HttpPost] 
public ActionResult Index(HttpPostedFileBase file) 
{ 
    if (file != null && file.ContentLength > 0) 
    { 
     var fileName = Path.GetFileName(file.FileName); 
     var path = Path.Combine(Server.MapPath("~/Images/Photo"), fileName); 
     file.SaveAs(path); 
    } 

    return RedirectToAction("Index");   
} 

답변

0

이것은 사용 권한 문제와 매우 유사합니다. 당신은 Images 폴더를 만들고 그것에게 읽기/쓰기 권한을 주었다고 말했지만 코드에서 볼 수있는 것에서는 Photo이라는 하위 폴더에 이미지를 저장하려고합니다. 따라서이 폴더도 생성했는지 확인하고 읽기/쓰기 권한도 부여하십시오. 또한 응용 프로그램이 호스팅되는 응용 프로그램 풀을 실행하도록 IIS에서 구성된 계정 인 올바른 계정에 권한을 부여해야합니다.

0

은이 코드를 사용하여보기에서

[HttpPost] 
public ActionResult Upload(System.Web.HttpPostedFileBase file) 
{ 
     string filename = Server.MapPath("~/files/somename"); 
     file.SaveAs(filename); 
     return RedirectToAction("Index"); 
} 

@{ 
    ViewBag.Title = "Upload"; 
} 
<h2> 
    Upload</h2> 
@using (Html.BeginForm(actionName: "Upload", controllerName: "User", 
         method: FormMethod.Post, 
         htmlAttributes: new { enctype = "multipart/form-data" })) 
{ 
    <text>Upload a photo:</text> <input type="file" name="photo" /> 
    <input type="submit" value="Upload" /> 
} 
관련 문제