1

ASP.NET C#Webアプリケーションは、jpg、png、docx、txtなどのさまざまなファイルをClientBinというフォルダーにアップロードします。Visual Studio 2010.NETIDEに付属しているVisualStudio2010.NETテストサーバーではすべて正常に動作します。

ただし、アプリケーションをIIS7サーバーに展開する場合は、アプリケーションのWebユーザーにファイルのアップロードを許可する必要があります。基本的にIIS7を使用してサーバーにログオンし、ClientBinというフォルダーのセキュリティプロパティを手動で変更します。このフォルダーには、最終的にjpg、png、docx、txtなどのコンテンツが含まれます。

---Webユーザーが正常にアップロードできるようにするための手動アプローチ---------------------------

Explorerでprojectfolder\ClientBinフォルダーを右クリックし、[プロパティ]を選択して、[セキュリティ]タブを選択します。「追加」をクリックして、適切なユーザーまたはグループを追加します。ASP.NETアカウントを強調表示し、目的のアクセスのチェックボックスをオンにします。---アップロードを正常に機能させるための手動アプローチ---------------------------

--アップロードしようとしたときにWebユーザーに例外エラーが発生するプログラムによるアプローチ------------------

String DirectoryPath = System.IO.Path.Combine(Server.MapPath("~/ClientBin/"));
DirectorySecurity specificDirectorySecurity = Directory.GetAccessControl(DirectoryPath);
specificDirectorySecurity.AddAccessRule(new FileSystemAccessRule("Users", FileSystemRights.Modify, AccessControlType.Allow));
specificDirectorySecurity.AddAccessRule(new FileSystemAccessRule("Administrators", FileSystemRights.Modify, AccessControlType.Allow));
specificDirectorySecurity.AddAccessRule(new FileSystemAccessRule("SYSTEM", FileSystemRights.Modify, AccessControlType.Allow));
Directory.SetAccessControl(DirectoryPath, specificDirectorySecurity);

--アップロードしようとしたときにWebユーザーに例外エラーが発生するプログラムによるアプローチ------------------

別のオンライン投稿では、web.configに次のように入力して問題を解決することを提案しています。

----プログラムによるアプローチの問題を解決する可能性のあるXML構成--------

アイデンティティimpersonate="true" userName = "ComputerName \ Administrator" password = "don"

----プログラムによるアプローチの問題を解決する可能性のあるXML構成--------

ただし、IDを真に偽装すると、セキュリティの問題が心配になります。

これを行うための最も安全で最も自動化された(プログラムによるソリューションを意味する可能性がある)方法は何ですか?

ありがとう、

新入社員

4

2 に答える 2

1

通常、アプリケーションにはディレクトリへの権限が付与され、アプリケーションはアップロードフォルダへのユーザーアクセスを管理します。

于 2012-08-14T18:16:07.373 に答える
0

全て:

C#がアップロードフォルダーのアクセス許可を変更する方法を理解できませんでしたが。

Microsoft Windows PowerShellは、アップロードフォルダーのアクセス許可をプログラムで変更できるようです。

アップロードフォルダの権限をプログラムで変更するコードのスニペットは次のとおりです。

$computerHostName = [System.Net.Dns]::GetHostName()

#These constants are used to set permissions
$inherit = [system.security.accesscontrol.InheritanceFlags]"ContainerInherit, ObjectInherit"

$propagation = [system.security.accesscontrol.PropagationFlags]::None

$colRights = [System.Security.AccessControl.FileSystemRights]"Modify"

$objType =[System.Security.AccessControl.AccessControlType]::Allow

#(MSDN Docs) The IIS_IUSRS Group has access to all the necessary file and system     resources
# so that an account, when added to this group, can seamlessly act as an application     pool identity.
#  IIS_IUSRS group by default includes the web users that log on to the Perls    Applications. 
#If a web user needs to upload resources to the folder within the Perls Web     Application that
# contains uploaded resource files then we need to ensure that the members of the
# IIS_IUSRS Group have permissions to add resource files to that particular Perls Web      Application upload folder.

#This determines which user is the guest user for IIS.  Windows Vista and 08 use the      IIS_USRS group, Previous version use
#IUSR_[MachineName]



  if ([environment]::osversion.Version.Major -eq 6) {
  $webUser="IIS_IUSRS"


  } else {

     $webUser="IUSR_" + $computerHostName

 }


$clientBinDirectoryPath = "D:\DeployedApplications\" + $umbrellaComponentName + "\" +     $siteWebComponentName + "\" + "ClientBin"

$perlsPivotErrorDirectoryPath = "D:\DeployedApplications\" + $umbrellaComponentName +      "\" + $siteWebComponentName + "\" + "PerlsPivotErrorDirectory"

$aclForClientBinDirectoryPath = Get-Acl $clientBinDirectoryPath


$accessRuleForClientBinDirectoryPath = New-Object     System.Security.AccessControl.FileSystemAccessRule($webUser, $colRights, $inherit,     $propagation, $objType)

$aclForClientBinDirectoryPath.AddAccessRule($accessRuleForClientBinDirectoryPath)

Set-Acl -aclobject $aclForClientBinDirectoryPath $clientBinDirectoryPath

$aclForPerlsPivotErrorDirectoryPath = Get-Acl $perlsPivotErrorDirectoryPath

$accessRuleForPerlsPivotErrorDirectoryPath  = New-Object     System.Security.AccessControl.FileSystemAccessRule($webUser, $colRights, $inherit,     $propagation, $objType)

$aclForPerlsPivotErrorDirectoryPath.AddAccessRule($accessRuleForPerlsPivotErrorDirectoryPath)

Set-Acl -aclobject $aclForPerlsPivotErrorDirectoryPath $perlsPivotErrorDirectoryPath
于 2013-02-26T20:11:18.427 に答える