IsolatedStorageException:无法创建商店目录

ped*_*des 4 c# asp.net isolatedstorage visual-studio

嗨,我必须在隔离空间中存储一些隐藏的信息.为此,我正在使用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();
Run Code Online (Sandbox Code Playgroud)

它在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范围,类型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 \网络\ UI\ViewStateHelper.cs:65 CSoft.Web.UI.Page.SavePageStateToPersistenceMedium(对象状态)在C:\ Projectos\FrameworkCS\CSoft.Web.Controls \网络\ UI\Page.cs:302
System.Web.UI.Page.SaveAllState()236
System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)1099

小智 7

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

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

问题是,您尝试使用GetUserStoreForAssembly,因为它需要具有隔离存储权限的用户,应用程序的默认IIS用户无法获得此权限.

有两种解决方案:

  1. 使用GetMachineStoreForAssembly

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

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

   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())
Run Code Online (Sandbox Code Playgroud)

GetUserStoreForAssembly位于:C:\ Documents and Settings\Gabe\Local Settings\Application Data\IsolatedStorage \

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


小智 7

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