Kieran Ojakangas
Kieran Ojakangas

Reputation: 535

Cannot deploy ASP.NET MVC with write permissions for specific folder

I've been trying to create a feature of error logging for the application so that, when enabled in web.config, an error log text file would be created in the server path ~/ErrorLogs folder.

However, despite trying to follow instructions on a link below, I still have a permission denied message when testing this on the IIS Server (which is version 10):

http://sedodream.com/2011/11/08/SettingFolderPermissionsOnWebPublish.aspx

Here's my project target wpp file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="SetupCustomAcls" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">  
  <ItemGroup>
    <MsDeploySourceManifest Include="setAcl">
      <Path>$(_MSDeployDirPath_FullPath)\ErrorLogs</Path>
      <setAclAccess>Read,Write</setAclAccess>
      <setAclResourceType>Directory</setAclResourceType>
      <AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
    </MsDeploySourceManifest>
  </ItemGroup>
</Target>

<Target Name="DeclareCustomParameters" AfterTargets="AddIisAndContentDeclareParametersItems">
  <ItemGroup>
    <MsDeployDeclareParameters Include="ErrorLogsSetAclParam">
      <Kind>ProviderPath</Kind>
      <Scope>setAcl</Scope>
      <Match>^$(_EscapeRegEx_MSDeployDirPath)\\ErrorLogs$</Match>
      <Description>Add write permission to the ErrorLogs folder.</Description>
      <DefaultValue>{$(_MsDeployParameterNameForContentPath)}/ErrorLogs</DefaultValue>
      <Value>$(_DestinationContentPath)/ErrorLogs</Value>
      <Tags>Hidden</Tags>
      <Priority>$(VsSetAclPriority)</Priority>
      <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
    </MsDeployDeclareParameters>
  </ItemGroup>
</Target>
</Project>

Can anyone advise on any additional steps I need to take so that these permissions are set automatically when I'm deploying the web application?

Upvotes: 1

Views: 1125

Answers (1)

Jalpa Panchal
Jalpa Panchal

Reputation: 12749

If you want to implement this requirement you need to follow below steps:

  • Select application in visual studio and right click and select "Unload project".
  • add below code in .csproj file.

Note: make sure you added folder proper path.

 <Target Name="SetupCustomAcls" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">
<ItemGroup>
  <MsDeploySourceManifest Include="setAcl">
    <Path>$(_MSDeployDirPath_FullPath)\test</Path>
    <setAclAccess>Read,Write</setAclAccess>
    <setAclResourceType>Directory</setAclResourceType>
    <AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
  </MsDeploySourceManifest>
  <MsDeploySourceManifest Include="setAcl">
    <Path>$(_MSDeployDirPath_FullPath)\bin</Path>
    <setAclUser>iusr</setAclUser>
    <setAclAccess>Read</setAclAccess>
    <setAclResourceType>Directory</setAclResourceType>
    <AdditionalProviderSettings>setAclUser;setAclResourceType;setAclAccess</AdditionalProviderSettings>
  </MsDeploySourceManifest>
</ItemGroup>

<Target Name="DeclareCustomParameters" AfterTargets="AddIisAndContentDeclareParametersItems">
<ItemGroup>
  <MsDeployDeclareParameters Include="testSetAclParam">
    <Kind>ProviderPath</Kind>
    <Scope>setAcl</Scope>
    <Match>^$(_EscapeRegEx_MSDeployDirPath)\\test$</Match>
    <Description>Add write permission to the Elmah folder.</Description>
    <DefaultValue>{$(_MsDeployParameterNameForContentPath)}/test</DefaultValue>
    <Value>$(_DestinationContentPath)/test</Value>
    <Tags>Hidden</Tags>
    <Priority>$(VsSetAclPriority)</Priority>
    <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
  </MsDeployDeclareParameters>
  <MsDeployDeclareParameters Include="BinSetAclParam">
    <Kind>ProviderPath</Kind>
    <Scope>setAcl</Scope>
    <Match>^$(_EscapeRegEx_MSDeployDirPath)\\Bin$</Match>
    <Description>Add read permission to the bin folder.</Description>
    <DefaultValue>{$(_MsDeployParameterNameForContentPath)}/bin</DefaultValue>
    <Value>$(_DestinationContentPath)/bin</Value>
    <Tags>Hidden</Tags>
    <Priority>$(VsSetAclPriority)</Priority>
    <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
  </MsDeployDeclareParameters>
</ItemGroup>

  • after adding code save the file and reload the project.

  • select project and right click and select "publish".

  • On the Publish page, click the icon labeled IIS, FTP, etc.

  • In the Publish Method list box, select Web Deploy: enter image description here

enter image description here

enter image description here

Regards, Jalpa

Upvotes: 1

Related Questions