2012-08-14 1 views
1

우리의 ASP.NET C# 웹 응용 프로그램은 jpgs, pngs, docx, txt 등과 같은 다양한 파일을 ClientBin이라는 폴더에 업로드합니다. Visual Studio 2010 .NET IDE와 함께 제공되는 Visual Studio 2010 .NET 테스트 서버에서 모든 것이 잘 작동합니다.ASP.NET C# 웹 응용 프로그램에서 업로드 폴더에 대한 권한을 부여하는 안전하고 자동화 된 방법은 무엇입니까?

그러나 IIS7 서버에 응용 프로그램을 배포하는 경우 웹 응용 프로그램에 파일 업로드 권한을 부여해야합니다. 기본적으로 IIS7을 사용하여 서버에 로그온 한 다음 jpgs, pngs, docx, txt 등과 같은 콘텐츠를 궁극적으로 포함해야하는 ClientBin 폴더의 보안 속성을 수동으로 수정합니다.

--- 성공적으로 업로드 할 웹 사용자 ---------------------------

Explorer에서 projectfolder \ ClientBin 폴더를 마우스 오른쪽 버튼으로 클릭하고 " 속성 "을 선택하고 보안 탭을 선택하십시오. 적절한 사용자 또는 그룹을 추가하려면 "추가"를 클릭하십시오. ASP.NET 계정을 강조 표시하고 원하는 액세스 상자를 선택하십시오. --- 업로드를 수동으로 만드는 수동 접근 방식 ---------------------------

- 여전히 웹을 제공하는 프로그래밍 방식 사용자가 여전히 웹 사용자에게 upload-하려고 예외 오류를 제공 ------------------

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

--Programmatic 접근 방식을 업로드하려고 예외 오류

: -----------------

또 다른 온라인 후 내가 Web.config의에서 다음을 입력하여이 문제를 해결 제안 프로그램 접근 --------

신원 가장 할로 문제를 해결할 수 ---- XML ​​구성 = "true"로는 userName = "컴퓨터 이름 \ 관리자" 암호 = "돈"

- - 프로그래밍 방식의 문제를 해결할 수있는 XML 구성 --------

그러나 신원을 true로 설정하면 보안 문제가 걱정됩니다.

프로그래밍 방식의 솔루션 일 수있는 가장 안전하고 자동화 된 방법은 무엇입니까?

감사합니다,

newemployee

+0

결코, 이제까지, 사용자가 응용 프로그램 폴더에 물건을 업로드 할 수 있습니다.처음 업로드되고 실행 된 스크립트는 애플리케이션을 파괴합니다. –

+0

@WiktorZychla 동의합니다. ASP.NET, IIS 또는 Windows에서 발견 된 결함 만 있으면 손상 될 수 있습니다. 바이너리를 외부 데이터 소스에 업로드하는 것이 좋습니다. – SilverlightFox

답변

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

@ chuck-conway Microsoft Windows PowerShell을 사용하여 프로그래밍 방식으로 업로드 폴더의 사용 권한을 수정하는 방법을 알아 냈습니다. – user1338998

1

일반적으로 응용 프로그램이 주어진 디렉토리에 대한 권리와 응용 프로그램이 사용자가 업로드 폴더에 대한 액세스를 관리합니다.

+0

그러나 응용 프로그램 web.config 파일에 다음을 입력하는 것이 좋습니다. identity impersonate = "true"userName = "ComputerName \ Administrator"password = "don"? – user1338998

+1

@ user1338998 아니요, 먼저 응용 프로그램에 관리자 권한이 없어야하며 응용 프로그램이 시스템 계정으로 이미 실행되고 있어야합니다. 시스템 계정 (응용 프로그램 풀에서 찾을 수 있음) 사용 권한을 부여하거나 응용 프로그램 풀에서 설정할 수있는 응용 프로그램 계정을 만들 수 있습니다. –

+0

NETWORK SERVICE 계정은 현재 개발중인 웹 응용 프로그램이있는 응용 프로그램 풀과 연결되어 있습니다. ClientBin의 사용 권한과 관련된 "Group 또는 UserNames"에 수동으로 추가 할 수 있습니다. 그러나 프로그래밍 방식으로 (또는 어떤 종류의 자동화 된 방식으로)이 작업을 수행 할 수 있는지 알고 싶습니다. 그렇다면 어떻게해야할까요? – user1338998

관련 문제