IsolatedStorageException:无法创建商店目录

嗨,我必须在隔离空间中存储一些隐藏的信息。 为此,我正在使用System.IO.Isolated类

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(); 

它在Windows XP中运行良好,但在生产服务器上是Windows 2003,它显示exception

System.IO.IsolatedStorage.IsolatedStorageException:无法创建商店目录。

我的asp.net项目文件夹中有Everyone完全控制权限。 注意CSoft.Core是由我创建的个人框架。

这是我的Stack Trace:

[IsolatedStorageException:无法创建商店目录。 (HRESULTexception:0x80131468)]
System.IO.IsolatedStorage.IsolatedStorageFile.nGetRootDir(IsolatedStorageScope范围)+0
System.IO.IsolatedStorage.IsolatedStorageFile.InitGlobalsNonRoamingUser(IsolatedStorageScope范围)+97
System.IO.IsolatedStorage.IsolatedStorageFile.GetRootDir(IsolatedStorageScope范围)+137
System.IO.IsolatedStorage.IsolatedStorageFile.GetGlobalFileIOPerm(IsolatedStorageScope范围)+213
System.IO.IsolatedStorage.IsolatedStorageFile.Init(IsolatedStorageScope范围)+56
System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope范围,类型domainEvidenceType,类型assemblyEvidenceType)+59
Coft.Core.IO.StorageHelper.Save(String fileName,String content)在c:\ Projectos \ FrameworkCS \ CSoft.Core \ IO \ StorageHelper.cs:18
Coft.Web.UI.ViewStateHelper.SerializeViewState(HttpContext context,Object state)在c:\ Projectos \ FrameworkCS \ CSoft.Web.Controls \ Web \ UI \ ViewStateHelper.cs:65 CSoft.Web.UI.Page.SavePageStateToPersistenceMedium(Object状态)在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

我知道这个用户已经解决了他们的问题,但是其他人正在寻找答案。 这篇文章并不完美,但它会指出你需要解决这个问题。

使用asp.net GetMachineStoreForAssembly似乎在大多数情况下都有效,并且它可能是从Web应用程序使用独立存储时所需的模式。 因为即使您使用GetUserStoreForAssembly,它也会被运行asp.net应用程序的用户帐户隔离,并且对于每个网站用户来说它总是相同的,除非您以某种方式将每个登录映射到Windows用户(哦,如果你是这样做就可以了。)

问题是你尝试使用GetUserStoreForAssembly,因为它需要一个拥有独立存储权限的用户,应用程序的默认IIS用户无法获得此权限。

有两种解决方案:

  1. 使用GetMachineStoreForAssembly

  2. 如果必须使用GetUserStoreForAssembly,则将App设置为以具有权限的用户身份运行。 文件夹权限无法解决此问题。 有几种方法可以获得安全设置。(IIS7)您可以在应用程序池中,或在基本设置>连接为,或在身份validation>匿名身份validation下进行设置。 我不确定用户需要什么权利,但这会让你朝着正确的方向前进。

这里有一些奖励代码,可能会帮助您找出问题:

  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位于:C:\ Documents and Settings \ Gabe \ Local Settings \ Application Data \ IsolatedStorage \

GetMachineStoreForAssembly位于:C:\ Documents and Settings \ All Users \ Application Data \ IsolatedStorage \

如果它在IIS上运行且应用程序池标识为NetworkService,则可以尝试转到应用程序池的高级设置,并将“加载用户配置文件”值设置为“True”。 为我工作。

我将IsolatedStorage文件更改为

使用(IsolatedStorageFile isoStore = IsolatedStorageFile.GetMachineStoreForAssembly()){}

而这项工作。

你是如何在服务器上运行的? 如果您在服务器上将其作为服务运行,则可能是分配用于运行该服务的用户出现问题。 确保使用在生产服务器上使用的相同用户进行测试。

正如约翰·桑德斯在评论中提出的那样,请发布更多的堆栈跟踪,包括可能的线路抛出这个描述。

但是,使用一些通灵调试技巧 ,我会在这里采取一些可能有帮助的狂野刺伤:

  1. GetStore和IsolatedStorageFileStream构造函数都可以抛出IsolatedStorageException
  2. “它在Windows XP中运行良好” – 当您在运行在您的(可能是管理员)凭据下运行的Web服务器中运行站点时,但当然是具有配置文件的用户,因此是隔离存储文件夹。
  3. “但是在生产时会抛出exception” – 当它在“网络服务”或其他没有配置文件的帐户下运行,或者与桌面类型权限交互时(不确定具体情况 – 主要是缺少一个这是一个杀手锏。

在生产中运行的网站是什么类型的帐户? 我假设不是用户能够登录到服务器并正确地与文件系统交互?