2010-12-02 8 views
2

Excel 파일을 업로드 할 때이 오류가 발생합니다. 누구든지 도와 줄 수 있습니까? 파일 뒤에업로드시 거부 된 파일 경로에 대한 액세스

Access to the path 'C:\Data\IronElements\Upload\AUMData\20101202 031815.xlsx' 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 'C:\Data\IronElements\Upload\AUMData\20101202 031815.xlsx' 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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

내 코드는 다음과 같은 구문을

DateTime date = DateTime.Now; 
       string FileName = Convert.ToString(date.ToString("yyyyMMdd hhmmss")); 
       Directory.CreateDirectory("C:\\Data\\IronElements\\Upload\\AUMData\\Schema"); 
       doesFileExists("C:\\Data\\IronElements\\Upload\\AUMData\\Schema"); 
       fileUpload.PostedFile.SaveAs("C:\\Data\\IronElements\\Upload\\AUMData\\" + FileName + ".xlsx"); 
       System.Threading.Thread.Sleep(5000); 
       string connectionString = WebConfigurationManager.ConnectionStrings["SQLConnection"].ConnectionString; 
       SqlConnection SqlConnect = new SqlConnection(connectionString); 

       try 
       { 
        SqlConnect.Open(); 
        SqlCommand cmdAssetUnderManagement = new SqlCommand("Exec_Insert_AUMAssetValue", SqlConnect); 
        cmdAssetUnderManagement.CommandType = CommandType.StoredProcedure; 
        cmdAssetUnderManagement.ExecuteNonQuery(); 

       } 


       catch (Exception ex) 
       { 
        Response.Write(ex.Message); 
       } 
       finally 
       { 
        SqlConnect.Close(); 
       } 
       lblAUMTA.Visible = true; 
       lblAUMTA.Text = "File Upload Completed"; 
      } 
    private void doesFileExists(string p) 
      { 
       p = string.Concat(p, "\\AUMSchema.xlsx"); 
       if (!File.Exists(p)) 
       { 
        fileUpload.PostedFile.SaveAs("C:\\Data\\IronElements\\Upload\\AUMData\\Schema\\AUMSchema.xlsx"); 
       } 
      } 

답변

4

확인이있는 폴더 C : \ 데이터 \ IronElements \ 업로드 \ AUMData는 NTFS는 문맥이 실행을 IIS하는 사용자에 대해 쓰기 권한을 가지고있다. 또한 C : \ Data \ IronElements \ Upload의 하위 폴더가 상위 폴더의 권한을 상속하는지 확인하십시오. 이렇게하려면 보안 탭에서 고급 버튼 -> 사용 권한 변경 ->이 개체에서 상속 가능한 권한으로 모든 하위 개체 사용 권한 바꾸기를 선택하십시오. -> Hit Ok

+0

읽기 및 쓰기 권한이 있습니다. – Sravanthi

+0

ASP.NET 프로세스가 실행중인 계정에 대한 사용 권한이 있는지 확인하십시오. 아, 그리고 그것이 당신이 생각하는 계정으로 돌아가고 있는지 확인하십시오. – JohnFx

+0

좋습니다. 이것은 좋은 생각이 아니지만 시도해보십시오. 해당 폴더의 Everyone 역할에 읽기/쓰기 권한을 할당하고 어떤 일이 발생하는지 확인하십시오. 그 후 업로드가 이루어져야합니다. – Davita

1

웹 세션이 실행되는 계정에 대한 권한이 없습니다. 해당 폴더에 쓰기. 일단 ASP.Net 계정 (또는 사용중인 계정)에 필요한 사용 권한을 부여하면 예상대로 작동해야합니다.

+0

네트워크 서비스를 통해 폴더에 액세스 할 수 있도록 폴더를 만들고 공유 폴더로 만들었습니다. 하지만 여전히 작동하지 않습니다. – Sravanthi

0

이와 같은 권한 문제를보다 잘 처리하려면 필자의 웹 사이트를 실행하기 위해 낮은 priv'ed 사용자를 만들어야합니다. 사용자는 웹 사이트 자체의 이름을 따서 지어 졌기 때문에 그것이 무엇인지에 대해 분명합니다.

그런 다음 해당 사용자는 올바른 폴더 (C : \ Data \ IronElements \ Upload \ AUMData)에서 perms 만 가져옵니다. DB 액세스를 제한하는 좋은 방법이기도합니다. 최소한의 권한으로 SQL에서 특정 사용자에 대한 로그인을 만듭니다.

1

이 응용 프로그램에 사용중인 app-pool으로 이동하여 ID를 '네트워크 서비스'로 변경하십시오. 비슷한 문제가 발생하여 동일한 방식으로 수정되었습니다.

관련 문제