Suppression d'un fichier, mais accès refusé

J'ai un mvc4 application avec entity framework.

Je veux supprimer un fichier, mais à chaque fois il dit:

Une exception de type 'System.UnauthorizedAccessException' s'est produite dans mscorlib.dll mais n'a pas été traitée dans le code utilisateur

Informations supplémentaires: le chemin d'Accès " G:\Mijn Documents\Mes Sites Web\Lolabikes - Copie\C#\ContosoUniversity\Images\' est refusé.

par cette ligne: System.IO.Fichier.Supprimer(chemin);

C'est la méthode:

public ActionResult DeleteFiles(int id)
        {           
                //var fileName = Path.GetFileName(id.FileName);

                var DirSeparator = Path.DirectorySeparatorChar;
                var path = Server.MapPath("~\\Images" + DirSeparator);//+ fileName.Replace('+', '_')));
               var file = db.lolabikerPhotos.Find(id);               
               System.IO.File.Delete(path);
               db.SaveChanges();           

            return Redirect(Url.Action("Edit", "Account") + "#tabs-3");

        }

Je viens de lancer l'application dans visual studio, comme ceci: http://localhost:41787/Account/Edit?UserId=hallo

Je l'ai déjà fait les choses suivantes:

Un accès complet à la carte, j'ai ajouté le Réseau de Services à la carte avec un contrôle total. Mais rien ne semble fonctionner. Je suis avec windows 7. Et je lance visual studio 2013 en tant qu'administrateur

Je le vois aussi:

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 <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

Ici, vous pouvez voir l'accès:

Suppression d'un fichier, mais accès refusé

J'essaie quelque chose comme ceci:

 <system.web>

    <identity impersonate="true" userName="Administrator" password="windowsPassword"/>
    <httpRuntime requestValidationMode="2.0"  maxRequestLength="1048576" executionTimeout="3600" />
    <compilation debug="true" targetFramework="4.5" />

    <pages validateRequest="false" />

    <!--<httpRuntime targetFramework="4.5" />-->


  </system.web>

J'ai ajouté ceci:

<identity impersonate="true" userName="Administrator" password="windowsPassword"/> 

OK, je peux exécuter l'application, mais elle donne toujours l'erreur:

Access to the path 'G:\Mijn Documents\My Web Sites\Lolabikes - Copy\C#\ContosoUniversity\Images\' 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 'G:\Mijn Documents\My Web Sites\Lolabikes - Copy\C#\ContosoUniversity\Images\' 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 <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 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: 


Line 489:                var path = Server.MapPath("~\\Images" + DirSeparator);//+ fileName.Replace('+', '_')));
Line 490:               var file = db.lolabikerPhotos.Find(id);               
Line 491:               System.IO.File.Delete(path);
Line 492:               db.SaveChanges();           
Line 493:

la permission:

Suppression d'un fichier, mais accès refusé

Onglet avancé:
Suppression d'un fichier, mais accès refusé

Changé onglet autorisations:

Suppression d'un fichier, mais accès refusé

J'ai édité mon action méthode comme ceci:

 public ActionResult DeleteFiles(int id)
        {           
                var fileName = Path.GetFileName(@"\\Koala.jpg");

                var DirSeparator = Path.DirectorySeparatorChar;
                var path = Server.MapPath(@"\\Images" + DirSeparator + fileName.Replace('+', '_'));
               var file = db.lolabikerPhotos.Find(id);
               LolaBikePhoto lola = db.lolabikerPhotos.Find(id);
               db.lolabikerPhotos.Remove(lola);
               System.IO.File.Delete(path);


               db.SaveChanges();           

            return Redirect(Url.Action("Edit", "Account") + "#tabs-3");

        }

Et c'est maintenant au travail!

source d'informationauteur Niels Savant