如何创建文件夹,并在同一时间指定他们的访问权限? [英] How do you create folders and specify access permissions on them at the same time?
问题描述
我有一个Windows窗体应用程序,它作为一种管理模块对ASP.NET Web应用程序。该web应用程序提供的多个国家中,并且当新的国家被添加到应用程序的数据中创建的文件夹。
I have a windows forms application which serves as a sort of administrative module for an ASP.NET web application. The web application serves multiple countries, and folders are created when new countries are added to the application data.
不幸的是新添加的国家我遇到与Web应用程序的例外,当我去尝试在这些文件夹写入文件:
Unfortunately on the newly added countries I run into an exception with the web application when I go and try to write files in the folders:
System.UnauthorizedAccessException: Access to the path 'C:\...' is denied.
通过使用ASP.NET模拟Web应用程序,很显然,默认的IIS用户(计算机名\\ IUSR_MACHINENAME)没有权限写入到该文件夹。
With the web application using ASP.NET impersonation, it's obvious that the default IIS user (MACHINENAME\IUSR_MACHINENAME) has no permissions to write into the folder.
我如何授予权限的文件夹后,创建默认的IIS用户?
How do I grant permission the the default IIS user upon folder creation?
据我所知,
System.IO.Directory.CreateDirectory(string path, DirectorySecurity directorySecurity)
应该这样做,但我不明白如何指定的 DirectorySecurity
对象名称的日志。
推荐答案
授予权限,创建目录和文件(读/写/修改/ ...)的工作进程组(类型为sysname \\ IIS_WPG
)要在其中创建新目录的父目录。请确保你设置的权限适用于该文件夹,子文件夹和文件
,则该权限将被继承为你创建新的文件夹,你会不会需要具体应用它们。而不是做这所有的App_Data的,我建议创建一个特定的子目录,只授予在该子目录的权限。如果你有包装盒上运行多个应用程序,你可能希望创建一个新用户的应用为运行,改变工作进程组ID,并授予仅允许特定用户。
Grant permission to create directories and files (read/write/modify/...) to the worker process group (sysname\iis_wpg
) to the parent directory of where you want to create the new directories. Make sure that you've set the permissions to apply to this folder, subfolders, and files
, then the permissions will be inherited for new folders you create and you won't need to apply them specifically. Rather than doing this for all of App_Data, I'd suggest creating a specific subdirectory and only granting permissions on that subdirectory. If you have multiple apps running on the box you might want to create a new user for the app to run as, change the id of the worker process group, and grant only permission to that specific user.
这篇关于如何创建文件夹,并在同一时间指定他们的访问权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!