私はwinformアプリケーションを実装しました。私は設定class.Iフォルダ設定ファイルがリダイレクトされたフォルダに置かれると、Configuration.Saveメソッドが不正アクセスエラーをスローします
Cの下の設定ファイルと一緒にexeファイルを保存使用して設定ファイルでアプリケーションのユーザー設定を保存する:ユーザーは\\ \のAppData \ローカル
これは通常のケースでは正常に動作しますが、私は例外を取得、ユーザーがその場合address.In一部のサーバーにAppDataフォルダをリダイレクトしている場合に問題に直面しています:不正な操作を実行しようとしました
を。
私はここにいくつかの同様の質問が見つかりましたが、それらのどれも任意の満足answers.IはConfiguration.Saveコマンドを実行する前に、設定ファイルを削除しようとしましたなかったが、それは例外を与える:
設定ファイルを別のプログラムによって変更されました。
この問題を解決するにはどうすればよいですか。
1.シェア:
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, Object exceptionContext)
at System.Security.AccessControl.NativeObjectSecurity.Persist(String
name, AccessControlSections includeSections)
at System.Security.AccessControl.FileSystemSecurity.Persist(String
fullPath)
at System.IO.File.SetAccessControl(String path, FileSecurity fileSecurity)
at System.Configuration.Internal.WriteFileContext.DuplicateTemplateAttributes(String source, String destination)
at System.Configuration.Internal.WriteFileContext.DuplicateFileAttributes(String source, String destination)
at System.Configuration.Internal.WriteFileContext.Complete(String
filename, Boolean success)
at System.Configuration.Internal.InternalConfigHost.StaticWriteCompleted(String
streamName, Boolean success, Object writeContext, Boolean assertPermissions) at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext, Boolean assertPermissions)
at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext)
at
System.Configuration.Internal.DelegatingConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext)
at System.Configuration.UpdateConfigHost.WriteCompleted(String
streamName, Boolean success, Object writeContext)
at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename,
ConfigurationSaveMode saveMode, Boolean forceUpdateAll)
at System.Configuration.Configuration.SaveAsImpl(String filename, ConfigurationSaveMode saveMode, Boolean forceSaveAll)
at UtilityClasses.ConfigurationHandler.UpdateConfigFile(String key, String value, Boolean param)
コードを共有してください –
@ S.Petrosovコードを追加してください。 –
問題は、アプリケーションが実行されているユーザーだけがそのパスに対するアクセス権を持っていないと思います。 –