C# 获取IIS中的临时文件夹
我正在WCF服务中使用System.IO.Path.GetTempPath()在IIS的临时文件夹路径中创建临时文件。 我希望得到C:\Users[user]\AppData\Local\Temp路径,但我得到的是C:\Windows\TempC# 获取IIS中的临时文件夹,c#,wcf,iis,C#,Wcf,Iis,我正在WCF服务中使用System.IO.Path.GetTempPath()在IIS的临时文件夹路径中创建临时文件。 我希望得到C:\Users[user]\AppData\Local\Temp路径,但我得到的是C:\Windows\Temp 如何获取预期路径?Kernel32.dll:GetTempPath()的文档可能会帮助您: //This code is you need, this code is getting current user temp directory. string
如何获取预期路径?Kernel32.dll:GetTempPath()的文档可能会帮助您:
//This code is you need, this code is getting current user temp directory.
string temp = System.Environment.GetEnvironmentVariable("TEMP");
//This method is getting system temp directory.
System.IO.Path.GetTempPath();
基本上,IIS是在一个没有定义USERPROFILE env变量的帐户下运行的,所以它使用TMP或TEMP
请记住,w3wp(IIS中的工作进程)通常作为DefaultAppPool运行,而不是作为分配了目录的实际用户运行
希望这有帮助 IIS中的应用程序池很可能不是在您的本地帐户下运行的(因此会获得不同的文件夹)。默认情况下,IIS出于安全原因使用特殊的受限帐户:但当前用户是什么?阅读凯文·戈斯的评论。