2011-01-17 4 views
0

아래 코드는 내 웹 사이트에서 사진을 삽입하는 데 사용됩니다. 사진을 삽입 할 수는 있지만 원격 컴퓨터로 전송할 때 오류 메시지가 표시됩니다. 여기ASP.NET FileUpload를 사용하여 파일을 저장할 수 없습니다. 액세스가 거부되었습니다.

Protected Sub dvPictureInsert_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvPictureInsert.ItemInserted 

    'If the record was successfully inserted, save the picture 
    If e.AffectedRows > 0 Then 

     'Determine the maximum pictureID for this user 
     Dim results As DataView = CType(maxPictureIDDataSource.Select(DataSourceSelectArguments.Empty), DataView) 
     Dim pictureIDJustAdded As Integer = CType(results(0)(0), Integer) 
     'Reference the FileUpload control 
     Dim imageUpload As FileUpload = CType(dvPictureInsert.FindControl("imageUpload"), FileUpload) 

     If imageUpload.HasFile Then 
      Dim baseDirectory As String = Server.MapPath("~/UploadedImages/") 
      imageUpload.SaveAs(baseDirectory & pictureIDJustAdded & ".jpg") 
     End If 

오류 메시지입니다 :

Server Error in '/please-god' Application. Access to the path 'D:\Hosting\4423045\html\please-god\UploadedImages\3.jpg' is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path 'D:\Hosting\4423045\html\please-god\UploadedImages\3.jpg' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:

Line 21: If imageUpload.HasFile Then Line 22:
Dim baseDirectory As String = Server.MapPath("~/UploadedImages/") Line 23:
imageUpload.SaveAs(baseDirectory & pictureIDJustAdded & ".jpg") Line 24: End If Line 25: End If Source File: D:\Hosting\4423045\html\please-god\PhotoAdmin\Default.aspx.vb Line: 23

Stack Trace:

[UnauthorizedAccessException: Access to the path 'D:\Hosting\4423045\html\please-god\UploadedImages\3.jpg' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7715167 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1162
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +61 System.IO.FileStream..ctor(String path, FileMode mode) +55
System.Web.HttpPostedFile.SaveAs(String filename) +99
System.Web.UI.WebControls.FileUpload.SaveAs(String filename) +23
PhotoAdmin_Default.dvPictureInsert_ItemInserted(Object sender, DetailsViewInsertedEventArgs e) in D:\Hosting\4423045\html\please-god\PhotoAdmin\Default.aspx.vb:23 System.Web.UI.WebControls.DetailsView.OnItemInserted(DetailsViewInsertedEventArgs e) +108
System.Web.UI.WebControls.DetailsView.HandleInsertCallback(Int32 affectedRows, Exception ex) +69
System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +134
System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) +274 System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +676
System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +113
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

+0

가능한 중복 [asp.net는 FileUpload 컨트롤 문제 : 디렉토리에 대한 액세스가 거부] (http://stackoverflow.com/questions/2863066/asp-net-fileupload-control-problem-access-to- directory-is-denied) – Shimmy

답변

1

당신은 IIS 또는 웹 사이트를 실행하는 서버가 해당 디렉토리에 쓸 수있는 권한이 있는지 확인해야 여기에 코드입니다. 폴더 -> 속성 -> 보안 탭을 선택하면됩니다.

도움이되지 않는 경우 이벤트 로그에서 다시 액세스하여 어떤 계정으로 액세스하려고했는지 확인할 수 있습니다.

또한 this 소식을 읽고 싶을 수도 있습니다.

0

올바른 권한을 가진 사용자에게 응용 프로그램 풀을 설정해도 web.config에서 가장이 설정되어 있으면이 오류가 발생합니다.

web.config에서이 줄을 삭제하면 가장이 해제됩니다.

<identity impersonate="true" /> 
관련 문제