【问题标题】:Access denied to path while writing xml in iis在 iis 中写入 xml 时拒绝访问路径
【发布时间】:2012-12-10 21:54:25
【问题描述】:
System.UnauthorizedAccessException: Access to the path 'C:\Inetpub\wwwroot\Spicee    Webservice\App_Data\Employee.xml' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32   rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding)
at ResturantService.InsertDatabaseXML(String servername, String dbusername, String dbpassword, String dbname, String port)

当我尝试编写一个 xml 文件时出现上述错误。当我从 VS2008 运行代码时,代码运行良好。

我知道这与 iis 文件夹的权限集有关。但是我不想做权限设置手册,因为我们的计划是通过网站部署包分发应用程序,用户不会有手动设置权限的想法。

另外,当我尝试使用以下 iisuser 代码设置文件夹权限时。

 Directory.CreateDirectory(sPathName);
        DirectoryInfo info = new DirectoryInfo(sPathName);
        DirectorySecurity security = info.GetAccessControl();

        security.AddAccessRule(new FileSystemAccessRule(@"TAG1\IUSR_TAG1", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
        security.AddAccessRule(new FileSystemAccessRule(@"TAG1\IUSR_TAG1", FileSystemRights.FullControl, InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));

        info.SetAccessControl(security); 

我收到此错误。

System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
at System.Security.AccessControl.Win32.SetSecurityInfo(ResourceType type, String name, SafeHandle handle, SecurityInfos securityInformation, SecurityIdentifier owner, SecurityIdentifier group, GenericAcl sacl, GenericAcl dacl)
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object exceptionContext)
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, AccessControlSections includeSections)
at System.Security.AccessControl.FileSystemSecurity.Persist(String fullPath)
at System.IO.Directory.SetAccessControl(String path, DirectorySecurity directorySecurity)
at System.IO.DirectoryInfo.SetAccessControl(DirectorySecurity directorySecurity)
at ResturantService.InsertDatabaseXML(String servername, String dbusername, String dbpassword, String dbname, String port)

请帮我解决这个问题。

提前致谢。

【问题讨论】:

    标签: iis access-denied folder-permissions


    【解决方案1】:

    那么,您需要更改用于部署站点的任何内容,以授予用于执行此代码的任何帐户的写入权限,或者您需要将其放在其他地方,或者您需要设置另一个帐户,该帐户可以这样做,这样您就不会将许可分发给每个人和他的狗。

    这与系统手动工作的方式没有什么不同。如果您以低权限用户身份登录,您不能只为自己分配更高的权限。您必须获得更高级别的授权才能执行此操作。这就像 UAC 命中或 SUDO。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-12
      • 2015-04-06
      • 2012-07-04
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多