2013-10-20 3 views
5

내 웹 사이트에 관리자 패널이있어 사용자가 파일 시스템에 이미지를 업로드 할 수 있습니다.ASP.NET에서 godaddy 파일 시스템으로 이미지 업로드

imageFile.SaveAs(galleryPath + fileName); 

그러나 권한 예외가 점점 : 는 단순히 C# 코드에서하고 있어요 '경로에

액세스를 D : \ 이미지 \ ... \ HTML을 호스팅 \ 갤러리 \ page2- img1.jpg ' 이 거부되었습니다.

설명 현재 웹 요청 을 실행하는 중 처리되지 않은 예외가 발생했습니다. 오류에 대한 정보와 코드에서 오류가 발생한 위치에 대한 정보는 에 대한 스택 추적을 검토하십시오. 예외 정보 : System.UnauthorizedAccessException : 경로 'D : \ Hosting ... \ html \ Images \ Gallery \ page2-img1.jpg'에 대한 액세스가 거부되었습니다.

권한을 어떻게 부여 할 수 있습니까?

+0

당신이 IIS에 그것을 실행하는 경우를 살펴 http://stackoverflow.com/questions/4877741/access-to-the-path-is-denied –

+1

을 쓰기 활성화 : 여기

자세한 내용입니다 서버 Cpanel에 대한 사용 권한? 나는 Arvixe에서 나의 것을 주최하고 있으며 똑같은 문제가있다. 코드를 사용하여 FTP없이 업로드하는 경우 쓰기 권한을 활성화해야합니다. –

답변

0

확인이 내보기

@using (Html.BeginForm("Upload", "Pictures", FormMethod.Post, new { enctype = "multipart/form-data" })) 
{ 
    @Html.AntiForgeryToken() 
    <div> 
    Title:<br/> 
    @Html.EditorFor(x => x.Title)<br/> 
    @Html.ValidationMessageFor(x => x.Title)<br/> 
    @Html.TextBoxFor(x => x.File, new { 
    type = "file" 
    })<br/> 
    @Html.ValidationMessageFor(x => x.File)<br/> 
    Description:<br/> 
    @Html.TextAreaFor(x => x.Description)<br/> 
    @Html.ValidationMessageFor(x => x.Description) 
    </div> 
    <div style="clear:both"></div> 
    <p><input type="submit" value="Save"/></p> 
} 

인이 내 시야 모델

public class UploadModel 
    { 
     [Required(ErrorMessage=("You have not selected a file"))] 
     public HttpPostedFileBase File { get; set; } 
     [Required(ErrorMessage = "Please enter a title")] 
     [StringLength(50)] 
     public string Title { get; set; } 
     [StringLength(400)] 
     public string Description { get; set; } 
    } 

이 내 컨트롤러 조치입니다.

[Authorize(Roles = "Approved")] 
    [HttpPost] 
    [ValidateAntiForgeryToken] 
    public ActionResult Upload(UploadModel m) 
    { 
     byte[] uploadedFile = null; 
     Byte123 xxx = new Byte123(); 
     if (m.File != null && !string.IsNullOrEmpty(m.Title)) 
     { 
      //var fileName = System.IO.Path.GetFileName(m.File.FileName); 
      //string c = m.File.FileName.Substring(m.File.FileName.LastIndexOf(".")); 
      // m.Title = m.Title.Replace(c, ""); 
      uploadedFile = new byte[m.File.InputStream.Length]; //you get the image as byte here but you can also save it to file. 

이것은 MVC 코드입니다. Web Forms를 사용하는 경우 코드가 더 짧아야합니다. 링크에서이 코드를 찾을 수 없으므로 코드를 게시했습니다. 또한 Cpanel을 사용하여 호스트에서 쓰기 권한이 활성화되어 있는지 확인해야합니다.

관련 문제