Ben McCormack
Ben McCormack

Reputation: 33078

How do I configure IIS or the web server to allow it to read and write files?

I'm trying to add functionality to a simple web service that will allow me to log information to an XML file on the hard drive where the application is located. When I employ the functionality in a Console version of the application, the data gets logged to:

bin\x86\Debug MySolution.MyProject\MessageLog\TestMessagess.xml.

However, when I try to write read from or write to the XML file in the ASP.NET application, I get a System.UnauthorizedAccessException with the message:

Accees to the path 'MessageLog' is denied.

I would like the log file to appear in the \bin folder of the application directory, so what settings in IIS or on the server itself would I need to change to allow my application to read from and write to that folder?

My Machine: I'm using Windows XP SP3 with ASP.NET 4.0.

Upvotes: 1

Views: 17405

Answers (3)

Ihor Kaharlichenko
Ihor Kaharlichenko

Reputation: 6260

As Russ said, you need to grant read/write permission to a user which used by IIS.

For IIS up to 6.0, the identity name is NETWORK SERVICE.

For IIS 7.0, permissions are to be granted on per application pool basis. The identity template is IIS APPPOOL\%POOL-NAME%. Therefore, if your site runs using the MyApp application pool you should grant read/write access to the IIS APPPOOL\MyApp user identity. That's the default behavior. You can also set a custom identity for an application pool (see more here).

Upvotes: 4

Claudio Redi
Claudio Redi

Reputation: 68400

Try giving appropriate permissions to Network Service user

Upvotes: 2

Russ
Russ

Reputation: 4163

This is a function of the server's security, not of IIS. From within Windows Explorer, browse to the folder or file and set the security to allow the user that IIS runs under to have access.

Upvotes: 1

Related Questions