asp.net System.UnauthorizedAccessException: Access to the path IIS 7.5

In Asp.Net su webserver IIS 7.5 l’errore System.UnauthorizedAccessException può essere risolto conferendo gli opportuni permessi all’ApplicationPool  in cui girà l’applicazione web asp.net.

Lo user che corrisponde ad un “ApplicationPoolIdentity” in IIS 7.5 è system user virtuale identificato nel modo seguente:

IIS AppPool\AppPoolName
es.
IIS AppPool\zipad.com

Garantire ad ASP.NET l’accesso a un file oppure ad una directory:

  • click pulsante destro in File Explorer su file/directory
  • scegliere “Properties” e selezionare il tab Security .
  • Click su  “Add” per aggiungere lo user appropriato in questo caso
    IIS AppPool\<ApplicationPoolName>
  • Evidenziare lo user ASP.NET e spuntare i boxes per selezionare il tipo di accesso desiderato.

Dettagli dell’errore

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:\mypath\Uploads\test1.txt’ 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 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:

myStream = File.CreateText(Request.PhysicalApplicationPath + “\\Uploads\\test1.txt”); // creating file

myStream.Write(form_vs +”\r\n”);

Risorse:

 

IIS 7.5

Schermata base di IIS 7.5 in windows Server 2008 R

windows IIS 7.5 finestra principale

windows IIS 7.5 finestra principale

 

Per gestire con un sito più domini utilizzare il numero IP e non impostare lo host name a livello di site binding.
Poi via IIRF agganciare i domini entranti operando un redirect 301 a seconda delle esigenze.

 

IIS 7.5 binding site

IIS 7.5 binding site no host name

Redirect IIRF del tipo

RewriteCond %{HTTP_HOST} ^(.*)ethdavi\.it$
RedirectRule ^(|/(.*))$ http://www.ethdavi.com/it/ [R=301]

RewriteCond %{HTTP_HOST} ^(.*)ethdavi\.(it|com)it$
RedirectRule ^(|/(.*))$ http://www.ethdavi.com/it/ [R=301]

 

IIS 7.5 HTTPS

IIS 7.5 HTTPS

IIS 7.5 HTTPS

 

In windows 2008 IIS per le funzioni di mail Server intergrato utilzza  IIS 6.0

windows 2008 IIS 6.0 email server

windows 2008 IIS 6.0 email server