Re: UnauthorizedAccessException: Can't write to file, but I can read i

From: Rutger Smit (DoDotNet_at_gmail.com)
Date: 09/03/04


Date: Fri, 03 Sep 2004 20:22:23 +0200

Lukeb wrote:

> Hello
> I've just developed an application in VS on my machine (w2k), c#.
> Everything worked just fine, but when i installed the web application on the
> company server (w2k3 server), everything worked still fine exept writing back
> into an xml file!
> The file i want to write to is stored in a dir. in the inetpub folder.
>
> I've been looking around on the internet for a long time now, but NOTHING
> worked!
> - I gave full trust in the .NET configuration (and tried much more)
> - added the ASPNET user
> - checked the machine.config
>
> I admitt the whole .net security stuff is verry new to me but i think i
> tried all the standart stuff.
>
> I'd be so glad if someone could help me out here!
>
> I will also post the exception that is thrown:
>
> System.UnauthorizedAccessException: Der Zugriff auf den Pfad
> D:\Inetpub\ApplicationData\ArtistSite\askArtist.xml wurde verweigert. at
> System.IO.__Error.WinIOError(Int32 errorCode, String str) at
> System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
> FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean
> bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode,
> FileAccess access, FileShare share) at System.Xml.XmlDocument.Save(String
> filename) at VL_CMS.EditXML.MyDataGrid_Update(Object sender,
> DataGridCommandEventArgs e)
>
>

Give "NETWORK SERVICE" write permissions on the dir/file.
In Win2k3 webserver it's not the IUSR_<machinename> and not the ASPNET
user that does write actions for a website. It's the NETWORK SERVICE (a
built-in security principle).

//Rutger



Relevant Pages

  • The info you requested
    ... System.IO.__Error.WinIOError(Int32 errorCode, String str) at ... FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean ... bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, ... FileAccess access, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: File IO Error!!!
    ... > at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess ... > access, FileShare share, Int32 bufferSize, Boolean useAsync, String ...
    (microsoft.public.dotnet.languages.csharp)
  • WS Development Kit (Technology Preview) Problem
    ... at System.IO.FileStream..ctor(String path, FileMode mode, ... FileAccess access, FileShare share, Int32 bufferSize, Boolean ... useAsync, String msgPath, Boolean bFromProxy) ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Receive Function Race Condition
    ... at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess ... access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, ...
    (microsoft.public.biztalk.general)
  • FileReceive Function RACING!!!!
    ... at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess ... access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, ...
    (microsoft.public.biztalk.general)