2010-12-02 19 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を確認してくださいました:\ DATA \ IronElements \アップロード\ AUMDataは、コンテキストが実行をIISているユーザーのためのNTFSの書き込み権限を持っています。また、C:\ Data \ IronElements \ Uploadのサブフォルダが親からのアクセス権を継承していることを確認してください。これを行うには、[セキュリティ]タブの[詳細]ボタンをクリックします。 - >アクセス許可の変更 - >このオブジェクトから継承可能なアクセス許可ですべての子オブジェクトアクセス権を置き換える - >ヒットOKを選択します。

+0

それは読み取りと書き込みのアクセス許可を持っています – Sravanthi

+0

ASP.NETプロセスが実行されているアカウントのアクセス許可があることを確認します。ああ、またそれがあなたが思っているアカウントの下で実行されていることを確認してください。 – JohnFx

+0

これは良い考えではありませんが、試してみてください。そのフォルダのEveryone役割に読み取り/書き込みを割り当て、何が起こるかを確認します。それ以降はアップロードが必要です。 – Davita

1

Webセッションが実行されているアカウントには、そのフォルダに書き込みます。 ASP.Netアカウント(または使用しているアカウント)に必要なアクセス許可を与えると、期待どおりに機能するはずです。

+0

ネットワークサービスをフルコントロールでアクセスするフォルダを作成し、共有フォルダとして作成しました。それでも動作しません – Sravanthi

0

私はこのような権限の問題をより良く扱うために、私たちのウェブサイトを運営するための低priv'edユーザーを作成します。ユーザーはウェブサイト自体の名前を付けられているので、それが何のためにあるのかは明らかです。

この場合、ユーザーは適切なフォルダ(C:\ Data \ IronElements \ Upload \ AUMData)のパーマネントのみを取得します。また、DBへのアクセスを制限する良い方法です - 最小限のprivでSQLでその特定のユーザーのログインを作成する。

1

このアプリケーションで使用しているアプリケーションプールに移動し、そのIDを「ネットワークサービス」に変更します。私は同様の問題に直面し、同じ方法で修正しました

関連する問題