Currently I have a standard web deployment project that installs my web application project into the standard inetpub location. I have a custom action that grants Network Service (for IIS, it detects and uses ASPNET for WinXP) write access to the web.config file. I have a Configuration.aspx page for administators to change various settings, some located in the web.config and some in a database record. In the VS web server everything works fine. I am assuming it is because it is running as my login which is an Administrator. However, when I deploy the application and run the save function I get the following exception: (Please note the text has been HTML Encoded because it gets written to the EventLog as XML
System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Access to the path 'C:\inetpub\wwwroot\Application\1v9oanyb.tmp' is denied. (C:\inetpub\wwwroot\GradProMsaWia\web.config) ---> System.UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot\Application\1v9oanyb.tmp' 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)
at System.CodeDom.Compiler.TempFileCollection.EnsureTempNameCreated()
at System.CodeDom.Compiler.TempFileCollection.AddExtension(String fileExtension, Boolean keepFile)
at System.CodeDom.Compiler.TempFileCollection.AddExtension(String fileExtension)
at System.Configuration.Internal.WriteFileContext..ctor(String filename, String templateFilename)
at System.Configuration.Internal.InternalConfigHost.StaticOpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext, Boolean assertPermissions)
at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext, Boolean assertPermissions)
at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext)
at System.Configuration.Internal.DelegatingConfigHost.OpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext)
at System.Configuration.UpdateConfigHost.OpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext)
at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll)
--- End of inner exception stack trace ---
at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll)
at System.Configuration.Configuration.SaveAsImpl(String filename, ConfigurationSaveMode saveMode, Boolean forceSaveAll)
at System.Configuration.Configuration.Save(ConfigurationSaveMode saveMode)
at Members_Admin_Configuration.SaveApplicationInformation()
I thought the only time ASPNET/IIS wrote the web.config to a temp file was when it wasn't allowed to edit the file. However, I ensured that they file is not readonly and it isn't being used by any other processes. I have found a "fix" for this by granting Network Service write access to the directory. However, I do not want to grant my application any file permissions besides the web.config file and a special Logging directory for flat file logging.
Does anyone know what I need to do to stop this error. The installation works perfectly fine on WinXP and it can write the web.config without any problems.
Thanks!