IsolatedStorageException: Unable to create the store directory

有些话、适合烂在心里 提交于 2019-12-20 00:57:11

问题


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.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
Stream writer = new IsolatedStorageFileStream(filename, FileMode.Create, isf);

IFormatter formatter = new BinaryFormatter();
formatter.Serialize(writer, appCollection.ToString());

writer.Close();

It works fine in Windows XP but on production server that is windows 2003 it shows exception

System.IO.IsolatedStorage.IsolatedStorageException: Unable to create the store directory.

I have a Everyone full control permissions in my asp.net project folder. Attention CSoft.Core is a personal Framework created by me.

This is my Stack Trace:

[IsolatedStorageException: Unable to create the store directory. (Exception from HRESULT: 0x80131468)]
System.IO.IsolatedStorage.IsolatedStorageFile.nGetRootDir(IsolatedStorageScope scope) +0
System.IO.IsolatedStorage.IsolatedStorageFile.InitGlobalsNonRoamingUser(IsolatedStorageScope scope) +97
System.IO.IsolatedStorage.IsolatedStorageFile.GetRootDir(IsolatedStorageScope scope) +137
System.IO.IsolatedStorage.IsolatedStorageFile.GetGlobalFileIOPerm(IsolatedStorageScope scope) +213
System.IO.IsolatedStorage.IsolatedStorageFile.Init(IsolatedStorageScope scope) +56
System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) +59
CSoft.Core.IO.StorageHelper.Save(String fileName, String content) in c:\Projectos\FrameworkCS\CSoft.Core\IO\StorageHelper.cs:18
CSoft.Web.UI.ViewStateHelper.SerializeViewState(HttpContext context, Object state) in c:\Projectos\FrameworkCS\CSoft.Web.Controls\Web\UI\ViewStateHelper.cs:65 CSoft.Web.UI.Page.SavePageStateToPersistenceMedium(Object state) in c:\Projectos\FrameworkCS\CSoft.Web.Controls\Web\UI\Page.cs:302
System.Web.UI.Page.SaveAllState() +236
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1099


回答1:


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\




回答2:


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.




回答3:


I changed IsolatedStorage file to

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

And this work.




回答4:


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.




回答5:


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?



来源:https://stackoverflow.com/questions/1035576/isolatedstorageexception-unable-to-create-the-store-directory

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