Wednesday, January 30, 2013

WebDeploy error: System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.

When trying to deploy a web application from Visual Studio, it failed with the following error message:

clip_image002

This error message didn’t help much so I logged on to the server where I found the following error info in the Event log:

User:

Client IP: 10.1.210.31

Content-Type: application/msdeploy

Version: 9.0.0.0

MSDeploy.VersionMin: 7.1.600.0

MSDeploy.VersionMax: 9.0.1631.0

MSDeploy.Method: Sync

MSDeploy.RequestId: 3e4d3744-90cf-4c95-85c9-28eb30970c3e

MSDeploy.RequestCulture: nl-BE

MSDeploy.RequestUICulture: en-US

ServerVersion: 9.0.1631.0

Skip: objectName="^configProtectedData$"

Provider: auto, Path:

A tracing deployment agent exception occurred that was propagated to the client. Request ID '3e4d3744-90cf-4c95-85c9-28eb30970c3e'. Request Timestamp: '8/01/2013 11:41:32'. Error Details:

System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.

   at System.Security.AccessControl.Win32.SetSecurityInfo(ResourceType type, String name, SafeHandle handle, SecurityInfos securityInformation, SecurityIdentifier owner, SecurityIdentifier group, GenericAcl sacl, GenericAcl dacl)

   at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object exceptionContext)

   at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, AccessControlSections includeSections, Object exceptionContext)

   at Microsoft.Web.Deployment.FileSystemSecurityEx.Persist(String path, Boolean isFile)

   at Microsoft.Web.Deployment.SetAclProvider.Add(DeploymentObject source, Boolean whatIf)

   at Microsoft.Web.Deployment.DeploymentObject.Update(DeploymentObject source, DeploymentSyncContext syncContext)

   at Microsoft.Web.Deployment.DeploymentSyncContext.HandleUpdate(DeploymentObject destObject, DeploymentObject sourceObject)

   at Microsoft.Web.Deployment.DeploymentSyncContext.SyncChildrenOrder(DeploymentObject dest, DeploymentObject source)

   at Microsoft.Web.Deployment.DeploymentSyncContext.ProcessSync(DeploymentObject destinationObject, DeploymentObject sourceObject)

   at Microsoft.Web.Deployment.DeploymentObject.SyncToInternal(DeploymentObject destObject, DeploymentSyncOptions syncOptions, PayloadTable payloadTable, ContentRootTable contentRootTable, Nullable`1 syncPassId)

   at Microsoft.Web.Deployment.DeploymentAgent.HandleSync(DeploymentAgentAsyncData asyncData, Nullable`1 passId)

   at Microsoft.Web.Deployment.DeploymentAgent.HandleRequestWorker(DeploymentAgentAsyncData asyncData)

   at Microsoft.Web.Deployment.DeploymentAgent.HandleRequest(DeploymentAgentAsyncData asyncData)

Based on the UnauthorizedAccessException, I’m guessing that I forgot to configure some security settings in IIS. So let’s try to fix this…

  • Open the IIS Manager. Select the web site you want to deploy to on the left. On the Features view on the right look for the Management block:

clip_image002[6]

  • Select IIS Manager Permissions and click on the Allow User… action in the Actions menu on the right.

clip_image004

  • The Allow User… dialog is loaded. If you have configured a specific account to manage web deploy select the IIS Manager radio button(otherwise choose the Windows radio button). Click on the Select… button to select a user.

clip_image006

  • Choose a user from the list and click OK.

clip_image008

  • Click OK again.

clip_image010

After doing this, the IIS Manager account (in this case WebDeployUser) can be used when you want to deploy through web deploy.

As a last step, we’ll have to give IIS the necessary rights to create folders and add files to the target location. So browse to the target folder and give the Local Service user ‘Full Control’ access rights.

That’s it…

No comments: