Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)返回的String.Empty [英] Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) returns String.Empty

查看:829
本文介绍了Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)返回的String.Empty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net MVC3应用程序。现在我想保存用户数据在

i have an asp.net mvc3 application. Now i want to save userdata in

C:\\用户{​​AppPoolUserAccount} \\应用程序数据\\漫游\\ MyProgramm ...

C:\Users{AppPoolUserAccount}\AppData\Roaming\MyProgramm...

在(Environment.SpecialFolder.ApplicationData) Environment.GetFolderPath的第一个电话我只得到,(的String.Empty)。
在第二个电话 Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)返回正确路径...

On first call of Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) i only get "" (String.Empty). On second call Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) returns correct path...

请注意:
该程序是在登录-上下文。我想保存的用户名和会话ID在一个XML文件
以prevent两个用户通过一个用户帐户登录同步。

Note: The routine is in a Login-Context. I want to save username and sessionID in a xml-file to prevent that two users are logged in simultaneously via one user-account.

为什么?

推荐答案

Environment.GetFolderPath 返回大部分SpecialFolder枚举值的空字符串,因为用户的用户配置文件您正在使用运行应用程序池未加载。

Environment.GetFolderPath returns empty strings for most of the SpecialFolder enum values because the user profile for the user you are using to run the app pool is not loaded.

您需要或者通过进入IIS管理器>应用程序池> YourAppPool>高级设置>加载用户配置文件,并将其值设置为true或打开一个命令提示符并配置应用程序池加载用户配置文件运行

You need to configure the app pool to load the user profile either by going into IIS Manager > Application Pools > YourAppPool > Advanced Settings > Load User Profile, and setting the value to "true" or by opening up a command prompt and running

appcmd set apppool "MyAppPool" -processModel.loadUserProfile:true

(通常你会在运行C这样的:\\ WINDOWS \\ Syswow64资料\\ INETSRV)。

(usually you'll run this in C:\Windows\SysWOW64\inetsrv).

下面是一对夫妇的更多的数据链接:

Here are a couple of links with more data:

  • loadUserProfile and IIS7 (This one says that loading the profile is the default, which it isn't, but it is correct otherwise. Maybe they changed the default between 7 and 7.5?)
  • Process Model Settings for an Application Pool

这篇关于Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)返回的String.Empty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆