2014-11-06 14 views
5

la mia applicazione che ho creato utilizzando ASP.NET e C# utilizza un percorso temporaneo per memorizzare un documento mentre viene letto e quindi lo elimina dopo:ASP.NET non è autorizzato ad accedere alla risorsa richiesta quando accede alla cartella temporanea

string path = string.Concat((Server.MapPath("~/temp/" + FileUpload1.FileName))); 

Array.ForEach(Directory.GetFiles((Server.MapPath("~/temp/"))), File.Delete); 

Grazie per l'aiuto. Il documento StockControl è un esempio e potrebbe essere importato da più computer su una rete. sulla base del messaggio di errore sembra che il mio file non viene caricato e salvato nella directory temp ...

percorso locale in fase di debug (OPERE):

C:\Users\USER\Documents\Visual Studio 2013\Projects\WebApplication5\WebApplication5\temp 

l'applicazione viene distribuita con successo Tuttavia quando ho allegare il file e premere "Importa", viene visualizzato un messaggio di errore: L'accesso al percorso 'C: \ inetpub \ wwwroot \ StockControl \ temp \ Book1.xls' è negato.

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:\inetpub\wwwroot\StockControl\temp\Book1.xls' 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 and IIS 7, and the configured application pool identity on IIS 7.5) 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 File 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.

+1

Esegui esattamente cosa dice il messaggio di errore: aggiungi al tuo web.config – Zilog

+1

L'errore dice che l'accesso al percorso è negato. Non potrebbe essere più ovvio di quello :) assicurarsi che l'identità del pool di applicazioni abbia accesso all'intera cartella principale dell'applicazione. – PoweredByOrange

risposta

5

davvero una semplice correzione per risolvere il mio problema, in IIS ho dovuto fare clic destro sul Pool di applicazioni e impostare .NET Framework V4 a integrato piuttosto che classica/

Un'altra soluzione era quella di impostare la cartella specifica a cui si stava accedendo per leggere/scrivere agli utenti che lo richiedevano, può essere eseguita da utenti unici o all'interno di un'organizzazione, un gruppo di utenti

1

Ho lo stesso problema.

Effettuate le seguenti modifiche per risolvere il problema.

(1) Sono andato alla cartella wwwroot. Tasto destro e scheda sicurezza. Fornito IISUSER per impostare il permesso di lettura e scrittura nella cartella wwwroot.

(2) Modificato il pool di applicazioni nel pool separato e impostato l'identità su Identità del pool di applicazioni.

Problemi correlati