2014-02-08 2 views
0

폴더에 파일을 쓸 때마다이 오류가 발생합니다.경로 'xxxxxxxxx'에 대한 액세스가 거부되었습니다.

다음
protected void ListAttachments(List<MessagePart> msgParts) 
    { 
     bool attachmentsFound = false; 
     StringBuilder b = new StringBuilder(); 
     b.Append("<ol>"); 
     foreach (MessagePart p in msgParts) 
     { 
      string contentType = p.Headers["Content-Type"]; 
      string contentDisposition = p.Headers["Content-Disposition"]; 
      Match m; 
      if (contentDisposition != null) 
      { 
       m = FilenameRegex.Match(contentDisposition); 
       if (m.Success) 
       { 
        attachmentsFound = true; 
        b.Append("<li><a href='Handler.ashx?fileName=" + m.Groups["filename"].Value + "'>").Append(m.Groups["filename"].Value).Append("</a></li>"); 
        Response.AppendHeader("content-disposition", "attachment; filename=" + m.Groups["filename"].Value); 
        Response.ContentType = "application/octet-stream"; 
        //Error Occurs 
        Response.TransmitFile(Server.MapPath(@"~/Files")); 
        Response.End(); 
       } 
      } 
      else if (contentType != null) 
      { 
       m = NameRegex.Match(contentType); 
       if (m.Success) 
       { 
        attachmentsFound = true; 
        b.Append("<li><a href='Handler.ashx?fileName="+m.Groups["filename"].Value+"'>").Append(m.Groups["filename"].Value).Append("</a></li>"); 
       } 
      } 
     } 
     b.Append("</ol>"); 
     if (attachmentsFound) 
      AttachmentsLiteral.Text = b.ToString(); 
     else 
      AttachementsRow.Visible = false; 
    } 

오류가 Access to the path 'F:\Gmail\Files' is denied처럼 발생

여기 내 코드입니다.

은 오류 세부 정보입니다 :

Server Error in '/Gmail' Application. 

Access to the path 'F:\Gmail\Files' 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 'F:\Gmail\Files' 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 <identity impersonate="true"/>, 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 160:     Response.AppendHeader("content-disposition", "attachment; filename=" + m.Groups["filename"].Value); 
Line 161:     Response.ContentType = "application/octet-stream"; 
Line 162:     Response.TransmitFile(Server.MapPath(@"~/Files")); 
Line 163:     Response.End(); 
Line 164:    } 

Source File: f:\Gmail\DisplayPop3Email.aspx.cs Line: 162 

Stack Trace: 


[UnauthorizedAccessException: Access to the path 'F:\Gmail\Files' is denied.] 
    System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7712175 
    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) +66 
    System.Web.HttpResponse.TransmitFile(String filename, Int64 offset, Int64 length) +134 
    System.Web.HttpResponse.TransmitFile(String filename) +12 
    DisplayPop3Email.ListAttachments(List`1 msgParts) in f:\Gmail\DisplayPop3Email.aspx.cs:162 
    DisplayPop3Email.Page_Load(Object sender, EventArgs e) in f:\Gmail\DisplayPop3Email.aspx.cs:90 
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 
    System.Web.UI.Control.OnLoad(EventArgs e) +99 
    System.Web.UI.Control.LoadRecursive() +50 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627 

답변

1

은 내가 ASP.NET에 근무 이후 시간이왔다,하지만 난 것입니다 .... 내가 그것을 고칠 수있는 방법을 가르쳐주세요 이 대답에 총을 맞는다. 첫째, 오류는 매우 분명합니다. 사용자 계정은 ASP.NET 프로세스가 실행되는 컨텍스트 아래의 NETWORK 서비스 계정이 F : \ Gmail \ Files 디렉터리에 액세스하지 못하는 것일 수 있습니다.

앞으로 진행하는 방법에 대한 포인터를 제공하는 this link을 참조하십시오. ASP.NET 프로세스가 보안 문제를 제기하지 않고 디스크 파일을 쓰거나 읽을 수 있도록하기위한 단계를 자세하게 설명합니다.

What is new in ASP.NET Data access (ASP.NET 3.0에 적용) 및 ASP.NET required Access Control Lists에 대한 자세한 내용은 아래 링크를 참조하십시오.

호프 이것은 현재 직면 한 문제를 해결하기위한 단계입니다.