IsolatedStorageException: Unable to create store directory

Hi, I need to store hidden information in an isolated space. For this, I use the System.IO.Isolated class, for example

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 on Windows XP, but on the production server, which is Windows 2003, it shows an exception

System.IO.IsolatedStorage.IsolatedStorageException: Unable to create storage directory.

My asp.net project folder has all the full permissions. Caution CSoft.Core is a personal structure created by me.

This is my stack trace:

[IsolStorageException: Unable to create storage directory. (Exception from HRESULT: 0x80131468)]
System.IO.IsolatedStorage.IsolatedStorageFile.nGetRootDir (IsolatedStorageScope Area) +0
System.IO.IsolatedStorage.IsolatedStorageFile.InitGlobalsNonRoamingUser (IsolatedStorageScope Area) +97
System.IO.IsolatedStorage.IsolatedStorageFile.GetRootDir (IsolatedStorageScope Area) +137
System.IO.IsolatedStorage.IsolatedStorageFile.GetGlobalFileIOPerm (IsolatedStorageScope Area) +213
System.IO.IsolatedStorage.IsolatedStorageFile.Init (IsolatedStorageScope area) +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 (state object) 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

+4
source share
5 answers

I changed the IsolStorage file to

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

And this work.

+3
source

I know that this user has already solved his problem, but for others they are looking for an answer. This post is not perfect, but it will tell you what you need to solve this problem.

With asp.net, GetMachineStoreForAssembly seems to work in most cases, and this is probably the desired mode when using isolated storage from a web application. Because even if you use GetUserStoreForAssembly, it will be isolated by the user account that launches the asp.net application, and it will always be the same for each user of the website, if you do not somehow associate each login with a Windows user (oh, and if you are doing this, then it will work).

The problem is that you are trying to use GetUserStoreForAssembly, because for this you need a user with rights to isolated storage, the default IIS user for applications does not get rights to this, I think.

There are 2 solutions:

  • use GetMachineStoreForAssembly

  • If you must use GetUserStoreForAssembly, install the application to run with user rights. This is not allowed by folder permissions. There are several ways to configure security. (IIS7). You can install it in the application pool or under the basic settings> "Connect as" or "Authentication"> "Anonymous Authentication". I don’t know exactly what rights the user needs, but it will help you move in the right direction.

Here is the bonus code that can 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 \

+7
source

If it works in IIS and the application pool identifier, this is NetworkService, you can try to go to the advanced settings of the application pool and set the value "Load user profile" to "True". Worked for me.

+5
source

How do you use this on the server? If you use it as a service on the server, you may have a problem with the user assigned to start the service. Make sure that you check with the same user that you use on the production server.

0
source

As John Saunders asks in his comment, please write more about the stack trace, including, if possible, lines that throw calculus.

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

  • Inventor isolated exception can be thrown as GetStore , and IsolStorageFileStream constructor
  • "It works fine in Windows XP" - when starting a site in Visual Studio, built-in to a web server under your (possibly administrative) credentials, but, of course, as a user with a profile and, therefore, a folder with isolated storage.
  • “But he throws an exception during production” - when he works under “Network Service” or with another account that does not have a profile, or “Interaction with desktop rights” (not sure about the specifics), this is basically the lack of a profile that is a killer).

Which account is the site running? I assume that this is not a user who can log into the server and work correctly with the file system?

0
source

Source: https://habr.com/ru/post/1286651/


All Articles