Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取IIS中的临时文件夹_C#_Wcf_Iis - Fatal编程技术网

C# 获取IIS中的临时文件夹

C# 获取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

我正在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 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出于安全原因使用特殊的受限帐户:但当前用户是什么?阅读凯文·戈斯的评论。