您好我必须在隔离空间中存储一些隐藏信息。为此,我使用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项目文件夹中有Everyone完全控制权限。注意CSoft.Core是由我创建的个人框架。

这是我的Stack Trace:

  

[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   scope,类型domainEvidenceType,类型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,   对象状态)in   C:\ Projectos \ FrameworkCS \ CSoft.Web.Controls \网络\ UI \ ViewStateHelper.cs:65   CSoft.Web.UI.Page.SavePageStateToPersistenceMedium(Object state)in   C:\ Projectos \ FrameworkCS \ CSoft.Web.Controls \网络\ UI \ Page.cs:302次点击   System.Web.UI.Page.SaveAllState()+236
  System.Web.UI.Page.ProcessRequestMain(布尔   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)   1099

有帮助吗?

解决方案 3

我将IsolatedStorage文件更改为

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

这项工作。

其他提示

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

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

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

有两种解决方案:

  1. 使用GetMachineStoreForAssembly

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

  3. 以下是一些奖励代码,可能会帮助您找出问题:

       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,您可以尝试转到应用程序池的高级设置并设置<!>“加载用户配置文件<!>”; value to <!> quot; True <!> quot;。为我工作。

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

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

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

  1. GetStore 可以抛出IsolatedStorageException href =“http://msdn.microsoft.com/en-us/library/3h3c0ahx.aspx”rel =“nofollow noreferrer”> IsolatedStorageFileStream 构造函数
  2. <!>“它在Windows XP中正常工作<!>”; - 当您在运行在您的(可能是管理员)凭据下运行的Web服务器中运行站点时,但当然是具有配置文件的用户,因此也是隔离存储文件夹。
  3. <!>“但是在生产时会抛出异常<!>”; - 当它在<!>“网络服务<!>”下运行时或者其他一些没有个人资料的帐户,或者与桌面类型权利交互(不确定细节 - 主要是缺少一个杀手的个人资料)。
  4. 该网站在生产中运行的是什么类型的帐户?我假设用户无法登录服务器并正确地与文件系统交互?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top