在Asp.net Web应用程序中使用如下代码获取独立存储区后,使用时有时会抛出“拒绝访问”、“无法创建主目录”的异常。
IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain, null, null);
分析其原因,可能是由于Asp.net帐号无权访问磁盘导致的。可以通过修改独立存储区的获取方式,来解决这个问题,改为按Machine获取。代码如下:
IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain, null, null);