IsolatedStorageException: Unable to create the store directory

后端 未结 5 1093
隐瞒了意图╮
隐瞒了意图╮ 2021-01-19 04:08

Hi I have to store some hidden information in Isolated space. For that I am using System.IO.Isolated class like

IsolatedStorageFile isf =     System.IO.Isola         


        
相关标签:
5条回答
  • 2021-01-19 04:32

    I know this user solved their problem already, but for others looking for an answer. This post is not perfect, but it will point you to what you need to solve this problem.

    With asp.net GetMachineStoreForAssembly seems to work in most cases, and it probably the desired mode when using isolated storage from a web app. Because even if you use GetUserStoreForAssembly, it will be isolated by the user account running the asp.net app and it will always be the same for each website user, unless you are somehow mapping each login to an windows user(oh and if you are doing this then it would be working).

    The problem is then you try to use GetUserStoreForAssembly because it needs a user with rights to isolated storage, the default IIS user for applications do not get rights for this I guess.

    There are 2 solutions:

    1. use GetMachineStoreForAssembly

    2. If you must use GetUserStoreForAssembly set the App to run as user with rights. This is not solved by folder permissions. There are several ways to get security setup.(IIS7) You can set it on the App pool, or under basic settings > Connect As, or under Authenication > Anonymous Authenication. I am not sure exactly what rights the user needs, but this will get you going in the right direction.

    Here is some bonus code than may help you figure out your problem:

       Dim storageFile As IsolatedStorageFile
        If Request("storage") = "user" Then
            storageFile = IsolatedStorageFile.GetUserStoreForAssembly()
        Else
            storageFile = IsolatedStorageFile.GetMachineStoreForAssembly()
        End If
    
        Response.Write(storageFile.GetType.GetField("m_RootDir", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance).GetValue(storageFile).ToString())
    

    GetUserStoreForAssembly is here: C:\Documents and Settings\Gabe\Local Settings\Application Data\IsolatedStorage\

    GetMachineStoreForAssembly is here: C:\Documents and Settings\All Users\Application Data\IsolatedStorage\

    0 讨论(0)
  • 2021-01-19 04:32

    I changed IsolatedStorage file to

    using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetMachineStoreForAssembly()) { }

    And this work.

    0 讨论(0)
  • 2021-01-19 04:33

    If it's running on IIS and application pool identity is NetworkService, You can try to go to advanced settings of application pool and set "Load user profile" value to "True". Worked for me.

    0 讨论(0)
  • 2021-01-19 04:44

    As John Saunders asks in his comment, please post more of the stack trace, including if possible the lines throwing the expception.

    However, using some psychic debugging skills, I'm going to take a couple of wild stabs here that might help:

    1. IsolatedStorageException can be thrown by both GetStore and the IsolatedStorageFileStream constructor
    2. "It works fine in Windows XP" - when you run the site in the Visual Studio built in web server running under your (probably admin) credentials, but certainly as a User with a profile, and therefore an Isolated Storage folder.
    3. "But on production it throws an exception" - when it's running under either "Network Service" or some other account that doesn't have a profile, or Interact with Desktop type rights (not sure of the specifics - it's mainly the lack of a profile that's a killer).

    What sort of account is the site running under in prodution? I assume it's not a user that is able to log on to the server and interact with the file system properly?

    0 讨论(0)
  • 2021-01-19 04:46

    How are you running this on the server? If you're running it as a service on the server, you may have a problem with the user assigned to run the service. Make sure you test with the same user you're using on the production server.

    0 讨论(0)
提交回复
热议问题