Isolated storage access permissions

主宰稳场 提交于 2019-12-11 11:47:15

问题


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.

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.

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?


回答1:


since the path to the isolated storage is generated by the OS and there is no way to find it out

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.



来源:https://stackoverflow.com/questions/7282569/isolated-storage-access-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!