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
Josh Twist - 31 Jan 2006 12:31 GMT
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/
Mana - 01 Feb 2006 04:53 GMT
Hi Josh,
I created one custom folder and gave ASPNET user necessary permissions.
It worked.
Thanks a lot.
Mana