无法部署具有特定文件夹写入权限的 ASP.NET MVC

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

我一直在尝试为应用程序创建错误日志记录功能,以便在 web.config 中启用时,将在服务器路径 ~/ErrorLogs 文件夹中创建错误日志文本文件.

然而,尽管尝试按照下面 link 中的说明进行操作,但在 IIS 服务器(版本 10)上测试时,我仍然收到权限被拒绝的消息:

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

这是我的项目目标 wpp 文件:

<?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>

任何人都可以建议我需要采取的任何其他步骤,以便在我部署 Web 应用程序时自动设置这些权限吗?

如果您想实现此要求,您需要按照以下步骤操作:

  • Select 在 visual studio 中应用并右击 select "Unload project".
  • 在 .csproj 文件中添加以下代码。

注意:确保您添加的文件夹路径正确。

 <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>

  • 添加代码后保存文件并重新加载项目。

  • select 项目并右击 select "publish".

  • 在“发布”页面上,单击标有 IIS、FTP 等的图标

  • 在发布方法列表框中,select Web 部署:

此致, 贾尔帕