UnauthorizedAccessException

D

DearManasi

Hi,

I have written a ASP.NET web service . It contains a method called
WriteMessage(). This method creates a .txt file on c drive and writes
some message to it.

Now I have created a ASP.NET web application. I am calling the
WriteMessage() method from this web application. But it is throwing
UnauthorizedAccessException.

The exception is as follows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
System.UnauthorizedAccessException: Access to the path
'c:\NSWebService.txt' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32
bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String
msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, FileOptions options)
at Service.WriteMessage()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

What should I do to obtain the nexessary permissions?
Please help.

Mana
 
J

Josh Twist

The problem here is that the ASPNET user account does not have
permissions to write to the C:\.

If you've managed to make your web service work when 'playing' with it
I'll wager that you are using the ASP.NET development server provided
with Visual Studio 2005 (.NET 2.0) - this operates under YOUR user
account permissions (probably Administrator). Don't use it, it's
dangerous for this very reason!

The quickest solution here is to give your ASPNET user account write
permissions to the files/folders necessary. I would strongly recommend
you create a custom folder and not give the ASPNET account full
permissions over your whole C:\ though! You could also consider
impersonation etc.

Josh
http://www.thejoyofcode.com/
 
M

Mana

Hi Josh,

I created one custom folder and gave ASPNET user necessary permissions.
It worked.
Thanks a lot.

Mana
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top