0
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フォルダーに設定されたアクセス許可に関連するものです。しかし、私たちの計画はWebサイト展開パッケージを介してアプリケーションを配布することであるため、アクセス許可設定マニュアルを実行したくありません。ユーザーはアクセス許可を手動で設定する考えがありません。

また、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)

この問題を解決するのを手伝ってください。

前もって感謝します。

4

1 に答える 1

0

サイトのデプロイに使用するものを変更して、このコードの実行に使用されているアカウントに書き込み権限を付与するか、別の場所に配置するか、これを実行できる別のアカウントを設定する必要があります。そのため、許可を全員と彼の犬に渡さないでください。

システムが手動で動作する方法と同じです。権限の低いユーザーとしてログオンした場合、自分自身に高い権限を割り当てることはできません。そのためには、より高いレベルで承認を受ける必要があります。UAC ヒット、または SUDO のようなものです。

于 2012-12-24T13:40:18.383 に答える