asp.netアプリケーションでは、いくつかのxmlファイルを自分のコンピュータのローカルフォルダにftpsするタスクがあります。私はそれらのファイルを読んでみたいですが、自分のローカルフォルダにコピーしたときには、ネットワークサービスのユーザーアカウントが設定されていません。だから、私の質問は、.NET C#で、あなたはプログラムで "Network Service"アカウントをフルコントロールでxmlファイルに追加するのですか?C#でファイルにセキュリティ権限をプログラムで追加する
5
A
答えて
2
following article( "C#のとNTFSアクセス許可を設定する")あなたを助けるでしょう:)
1
このコードを試してみてくださいヘルプ
場合public static bool CheckReadWriteAccces(string filePath, System.Security.AccessControl.FileSystemRights fileSystemRights)
{
FileInfo fileInfo = new FileInfo(filePath);
string str = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToUpper();
foreach (System.Security.AccessControl.FileSystemAccessRule rule in fileInfo.GetAccessControl().GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{
if (str == rule.IdentityReference.Value.ToUpper())
return ((rule.AccessControlType == System.Security.AccessControl.AccessControlType.Allow) && (fileSystemRights == (rule.FileSystemRights & fileSystemRights)));
}
return false;
}
/// <summary>
/// Make a file writteble
/// </summary>
/// <param name="path">File name to change</param>
public static void MakeWritable(string path)
{
if (!File.Exists(path))
return;
File.SetAttributes(path, File.GetAttributes(path) & ~FileAttributes.ReadOnly);
}
0
答えはFileSecurityクラスです。
http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesecurity.aspx
4
次のコード例は、追加したファイルからアクセス制御リスト(ACL)エントリを削除するFileSecurityクラスを使用FileSecurity class in MSDN
を参照してください。この例を実行するには、有効なユーザーまたはグループアカウントを指定する必要があります。
using System;
using System.IO;
using System.Security.AccessControl;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
try
{
string fileName = "test.xml";
Console.WriteLine("Adding access control entry for "
+ fileName);
// Add the access control entry to the file.
AddFileSecurity(fileName, @"DomainName\AccountName",
FileSystemRights.FullControl, AccessControlType.Allow);
Console.WriteLine("Removing access control entry from "
+ fileName);
// Remove the access control entry from the file.
RemoveFileSecurity(fileName, @"DomainName\AccountName",
FileSystemRights.FullControl, AccessControlType.Allow);
Console.WriteLine("Done.");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
// Adds an ACL entry on the specified file for the specified account.
public static void AddFileSecurity(string fileName, string account,
FileSystemRights rights, AccessControlType controlType)
{
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
}
// Removes an ACL entry on the specified file for the specified account.
public static void RemoveFileSecurity(string fileName, string account,
FileSystemRights rights, AccessControlType controlType)
{
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Remove the FileSystemAccessRule from the security settings.
fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
}
}
}
関連する問題
- 1. J2ME:プログラムでセキュリティ権限を設定する
- 2. marshmallowでロケーション権限を追加する
- 3. WPFのファイルへの書き込み権限のプログラム追加
- 4. Firebaseセキュリティ権限
- 5. 追加の権限
- 6. TYPO3にsys_categoryを追加する権限
- 7. シルバーストライプの「セキュリティ」権限
- 8. Tomcatセキュリティ権限エラー
- 9. RESTでのセキュリティ、ユーザーをグループにプログラムで追加する
- 10. webserviceにプログラムでセキュリティを追加する方法
- 11. 権限をプログラムで拒否する - Android
- 12. ウェブサイトのセキュリティ権限を変更する
- 13. セキュリティ例外:READ_EXTERNAL_STORAGE権限
- 14. メディアdjangoのメディアファイルに権限を追加できますか?
- 15. liferayでロールのカスタム権限を追加する方法6.2 ga3
- 16. sharepointでメモの権限を追加する
- 17. Facebookのアプリ内で追加の権限を付与する
- 18. C#プログラムでフォントをPDFに追加
- 19. symfonyセキュリティでダイナミックセキュリティ権限を取得する方法
- 20. Swaggerで役割/権限セキュリティを定義する方法
- 21. プログラムでDjangoでグループと権限を作成するには?
- 22. プログラムでトラストストアにcacertsファイルを追加
- 23. cプログラム:書き込み権限のないファイルを削除()する理由
- 24. facebookにaddtional権限を追加するには
- 25. C#でプログラムでメタタグを追加
- 26. EnvDTEで既存のC#ファイルに関数をプログラムで追加する
- 27. プログラムでビューをプログラムに追加する
- 28. uilistboxにプログラムでプログラムを追加する
- 29. ブロッキングのないファイルのセキュリティ権限の変更をキャッチ
- 30. gitはルート権限のみを持つファイルを追加できません