0

As part of installer code, we are trying to make changes to IIS (check and create virtual directory, followed by adding a section to its web.config file.

Installer was working fine till recently a strange error started haunting us and blocking the installer from proceeding

Error says /Core/Service/UserService failed. Reason: Filename: \?\ c:\website1\Core\Common\Service\userService\web.config Error: cannot write configuration file

Please note that "Default Web Site/Core/Service/UserService" is a virtual directory under "Default Web Site/Core" virtual directory in IIS.

"Default Web Site/Core" has physical path of c:\website1\Core\Common whereas "Default Web Site/Core/Service/UserService" is created with physical path of "c:\website1\Core\Service\UserService"

Not sure why error is pointing towards wrong folder path for web.config.

Code we have used is like this

using (ServerManager mgr = new ServerManager())
{
  //code to add virtual path to root website (default web site)
  mgr.CommitChanges();
}
using (ServerManager mgrpolicy = new ServerManager())
{
  Configuration config = mgrpolicy.GetWebConfiguration("Default Web Site","/Core/Service/UserService");
ConfigurationSection hndlesection = config.GetSection("system.webserver/handlers");
hndlesection["accessPolicy"] = "Read,Write"; //this value is dynamic based on installer input but hardcoded here for your reference.

  mgrpolicy.CommitChanges(); //issue comes after this line
}

we are running this installer on .net 4.8 windows application where the above code runs as part of a class library pointing to namespace System.Web.Administration.

Installer user is always system administrator and thus has all privileges.

Sri Katte
  • 67
  • 7
  • Please also note that the initial physical path used to create the virtual directory has a template web.config with some standard entries. It does not have system.webserver node to begin with. Attempt is to add this section after creating the virtual directory. – Sri Katte Jun 20 '22 at 21:06
  • Usually, this error is caused by insufficient permissions. Since the user you are using is the sysadmin, this can be ruled out. Another possible cause of the problem is lack of disk space, you can check it. – JennyDai Jun 21 '22 at 09:43
  • Appreciate your response JennyDai. We have over 20GB of diskspace. Guess that rules it out too. – Sri Katte Jun 22 '22 at 10:22
  • This error message can also appear if the physical folder is on a network drive instead of a local drive. By default the permissions on such drives appear to be different. For example, while the local drive location grants permission to the local computer user, the network location does not. Of course, this is just a guess. I think you can see if there is any error message in the event viewer. – JennyDai Jun 23 '22 at 06:35

0 Answers0