【问题标题】:IsolatedStorageException: Unable to create the store directory隔离存储异常:无法创建存储目录
【发布时间】:2009-06-23 22:24:12
【问题描述】:

您好,我必须在隔离空间中存储一些隐藏信息。为此,我使用 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 的生产服务器上却显示异常

System.IO.IsolatedStorage.IsolatedStorageException:无法创建存储目录。

我在我的 asp.net 项目文件夹中拥有所有人完全控制权限。注意CSoft.Core是我自己创建的个人Framework。

这是我的堆栈跟踪:

[IsolatedStorageException:无法创建存储目录。 (来自 HRESULT 的异常: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
CSoft.Core.IO.StorageHelper.Save(字符串文件名,字符串内容)在 c:\Projectos\FrameworkCS\CSoft.Core\IO\StorageHelper.cs:18
CSoft.Web.UI.ViewStateHelper.SerializeViewState(HttpContext 上下文, 对象状态)在 c:\Projectos\FrameworkCS\CSoft.Web.Controls\Web\UI\ViewStateHelper.cs:65 CSoft.Web.UI.Page.SavePageStateToPersistenceMedium(对象状态)在 c:\Projectos\FrameworkCS\CSoft.Web.Controls\Web\UI\Page.cs:302
System.Web.UI.Page.SaveAllState() +236
System.Web.UI.Page.ProcessRequestMain(布尔值 includeStagesBeforeAsyncPoint,布尔型 includeStagesAfterAsyncPoint) +1099

【问题讨论】:

  • 请发布完整的异常,包括所有 InnerException。捕获异常,然后发布 ex.ToString() 的结果。

标签: c# asp.net visual-studio isolatedstorage


【解决方案1】:

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

【讨论】:

  • 对我也有用,非常感谢。其实我的是 ApplicationPoolIdentity
【解决方案2】:

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

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

问题是你尝试使用 GetUserStoreForAssembly 因为它需要一个具有隔离存储权限的用户,我猜应用程序的默认 IIS 用户没有权限。

有两种解决方案:

  1. 使用 GetMachineStoreForAssembly

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

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

   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\

【讨论】:

  • 注意:一些用户配置文件(例如 NetworkService)位于 C:\Windows\ServiceProfiles 下
【解决方案3】:

我将独立存储文件更改为

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

还有这项工作。

【讨论】:

    【解决方案4】:

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

    【讨论】:

      【解决方案5】:

      正如 John Saunders 在他的评论中所问的,请发布更多的堆栈跟踪,如果可能的话,包括抛出异常的行。

      但是,使用一些psychic debugging skills,我将在这里采取一些可能会有所帮助的狂野刺伤:

      1. GetStoreIsolatedStorageFileStream 构造函数都可以抛出 IsolatedStorageException
      2. “它在 Windows XP 中运行良好” - 当您在 Visual Studio 内置 Web 服务器中运行该站点时,该服务器在您(可能是管理员)凭据下运行,但肯定是作为具有配置文件的用户,因此是独立存储文件夹。
      3. “但在生产中它会引发异常” - 当它在“网络服务”或其他没有配置文件的帐户下运行时,或与桌面类型权限交互时(不确定具体情况 - 主要是缺少一个杀手级的个人资料)。

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

      【讨论】:

        猜你喜欢
        • 2012-05-25
        • 2013-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-23
        相关资源
        最近更新 更多