隔离的存储访问权限 [英] Isolated storage access permissions

查看:142
本文介绍了隔离的存储访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将一些数据存储在隔离存储中的应用程序.数据与Machine-Assembly范围一起存储,以便给定计算机上的所有用户都可以访问此数据.

I have an application that stores some data in isolated storage. The data is stored with the Machine-Assembly scope so that all users on the given machine could access this data.

在管理员帐户下,一切似乎都可以正常工作,但是一旦我们在来宾帐户下测试了我们的应用程序,我们便遇到了用户权限限制.似乎隔离存储只是由OS生成的简单文件夹,可能会对用户访问这些文件夹有一些限制.

Everything seemed to work just fine under admin account, but as soon as we've tested our app under guest account we've run into user permission restrictions. It seems that isolated storage, being just a simple folder generated by the OS, can have some restrictions on user access to these folder.

在我的情况下,默认情况下,来宾帐户设置了读/写权限,但是一旦我们尝试删除管理员帐户下存储在文件中的文件,由于来宾帐户没有访问权限,我们便遇到了异常删除其他用户创建的文件的权限.

In my case guest account by default had read/write permissions set, but as soon as we tried to delete a file that was placed in the storage under admin account we've run into an exception since guest account didn't have rights to delete files created by another user.

因此,每次来宾尝试使用应用程序中的某些功能(要求删除其他用户创建的文件)时,我们都会崩溃.

As a result we get a crash each time guest tries to use some of the features in the app that require deletion of the files created by another user.

我认为也许我可以在尝试进行删除之前尝试检查guest虚拟机具有的权限,并警告他,由于他没有足够的权限,所以他不能使用这些功能,但是由于通往隔离存储的路径是由操作系统生成的,因此无法找到它(除了对文件系统进行完整遍历),因此无法检查来宾帐户拥有的权限.

I thought that perhaps I could try to check what permissions guest has prior to trying to proceed with deletion and warn him that he can not use these features since he doesn't have enough rights, but since the path to the isolated storage is generated by the OS and there is no way to find it out (other than doing a full traversal of the file system), so there's no way to check what rights guest account has.

也许有人对此有任何建议吗?

Perhaps someone has any suggestions regarding this?

推荐答案

由于隔离存储的路径是由操作系统生成的,因此无法找到它

有,但是您必须使用反射.这就是我所使用的(在这种情况下,是一个用户存储,但是想法是相同的):

There is, but you'll have to use reflection. This is what I use (in this case a user store but the idea is the same):

string path;
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
{
    using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fileNamePlusExtension, FileMode.Create, isf))
    {
      stream.Write(content, 0, content.Length);
      FieldInfo pi = stream.GetType().GetField("m_FullPath", BindingFlags.Instance | BindingFlags.NonPublic);
      path = pi.GetValue(stream).ToString();
    }
}

我不知道为什么将来可能没有内置的方法来获取这样的文件.

I dont't know why there's not a built-in way to get to such a file, maybe in the future.

也许您可以创建文件,然后设置来宾帐户的权限.

Maybe you can create the file and then set the permissions for the guest account.

这篇关于隔离的存储访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆