469,621 Members | 1,678 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

Access denied when writting to Application directory

Hello,

I know the problem I'm having has been mentioned several time...
However, the answers provided are not crystal clear.

Here is my problem:
I'm building a small web service that I will host on an internet Server
provider site (eg: WebMatrixHosting)
To be able to trace how it reacts, I want to write information in a log
file. To do so, I want to use a tracelistener and write the information in a
log file located in the application directory.
Here is a snippet of what I do:

gLogFileSwitch = new TraceSwitch("LogFileSwitch", "Local File Trace
Switch");
HttpRequest currRequest = HttpContext.Current.Request;
string strPath = currRequest.MapPath(currRequest.ApplicationPath);
Trace.Listeners.Add(new TextWriterTraceListener(strPath +
@"\SmallGame.log"));

Doing this, I receive an "access denied error".
What is the correct way to go?

Thanks,
José

Nov 18 '05 #1
5 1036
Does you files have write access for ASP.NET?

--
Rocky Moore
www.HintsAndTips.com - ~ Developer Tips Welcome ~
www.RJSoft.com/Products/RJContentPanel/ - Free web user content control!

"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> wrote in message
news:#h**************@TK2MSFTNGP09.phx.gbl...
Hello,

I know the problem I'm having has been mentioned several time...
However, the answers provided are not crystal clear.

Here is my problem:
I'm building a small web service that I will host on an internet Server
provider site (eg: WebMatrixHosting)
To be able to trace how it reacts, I want to write information in a log
file. To do so, I want to use a tracelistener and write the information in a log file located in the application directory.
Here is a snippet of what I do:

gLogFileSwitch = new TraceSwitch("LogFileSwitch", "Local File Trace
Switch");
HttpRequest currRequest = HttpContext.Current.Request;
string strPath = currRequest.MapPath(currRequest.ApplicationPath);
Trace.Listeners.Add(new TextWriterTraceListener(strPath +
@"\SmallGame.log"));

Doing this, I receive an "access denied error".
What is the correct way to go?

Thanks,
José


Nov 18 '05 #2
> I want to write information in a log file. To do so, I want to
use a tracelistener and write the information in a log file
located in the application directory. [...]
Doing this, I receive an "access denied error".
What is the correct way to go?


You need you loosen security settings on your log file, the account
IUSR_MACHINENAME needs write access to the file.

Create the file manually (e.g. using Notepad).
Right-click the file, choose Properties.
On the Security tab, add IUSR_MACHINENAME (MACHINENAME being your machine's
name).
Allow Read and Write access for this account.

Martin.
Nov 18 '05 #3
Thanks to both of you for the answer,

Applying your proposal solve the problem.
I will also update an XML file (where I will store usage information).
Is this the way to go. I mean : create initial files and give access to
those files?

Thanks,
José

"Martin Maat" <du***@somewhere.nl> a écrit dans le message de
news:10*************@corp.supernews.com...
I want to write information in a log file. To do so, I want to
use a tracelistener and write the information in a log file
located in the application directory. [...]
Doing this, I receive an "access denied error".
What is the correct way to go?
You need you loosen security settings on your log file, the account
IUSR_MACHINENAME needs write access to the file.

Create the file manually (e.g. using Notepad).
Right-click the file, choose Properties.
On the Security tab, add IUSR_MACHINENAME (MACHINENAME being your

machine's name).
Allow Read and Write access for this account.

Martin.

Nov 18 '05 #4
"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Thanks to both of you for the answer,

Applying your proposal solve the problem.
I will also update an XML file (where I will store usage information).
Is this the way to go. I mean : create initial files and give access to
those files?


It is the most straightforward way. If you intend to have a lot of files to
be written to that way and you need to create them from code, you may want
to try to set access rights for a folder and create all files in that
folder. My suggestion can get a bit cumbersome, especially if you deploy the
site to another machine or have to reinstall the lot for some reason.

Another thing to be aware of is synchronization. As your site gets more hits
and they come in simultaniously, the file may not be available for writing
because it is being written to on behalf of another visitor. You may want to
use a static XmlDocument member in your application class and use lock
statements with that or use mutexes to keep requests from getting in each
others' ways.

Martin.
Nov 18 '05 #5
Thanks for your detailled answer.

José
"Martin Maat" <du***@somewhere.nl> a écrit dans le message de
news:10*************@corp.supernews.com...
"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Thanks to both of you for the answer,

Applying your proposal solve the problem.
I will also update an XML file (where I will store usage information).
Is this the way to go. I mean : create initial files and give access to
those files?
It is the most straightforward way. If you intend to have a lot of files

to be written to that way and you need to create them from code, you may want
to try to set access rights for a folder and create all files in that
folder. My suggestion can get a bit cumbersome, especially if you deploy the site to another machine or have to reinstall the lot for some reason.

Another thing to be aware of is synchronization. As your site gets more hits and they come in simultaniously, the file may not be available for writing
because it is being written to on behalf of another visitor. You may want to use a static XmlDocument member in your application class and use lock
statements with that or use mutexes to keep requests from getting in each
others' ways.

Martin.

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Fabian von Romberg | last post: by
4 posts views Thread by RichB | last post: by
3 posts views Thread by jliusolar | last post: by
12 posts views Thread by Chad Crowder | last post: by
4 posts views Thread by Martin | last post: by
3 posts views Thread by David Thielen | last post: by
5 posts views Thread by rn5a | last post: by
8 posts views Thread by =?Utf-8?B?dHVtYQ==?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.