【问题标题】:Get Temporary folder in IIS获取 IIS 中的临时文件夹
【发布时间】:2017-02-12 12:37:41
【问题描述】:

我在我的 WCF 服务中使用 System.IO.Path.GetTempPath() 在 IIS 的临时文件夹路径中创建一个临时文件。 我期待得到 C:\Users[user]\AppData\Local\Temp 路径,但我得到的是 C:\Windows\Temp

我怎样才能得到预期的路径?

【问题讨论】:

  • 很有可能您在 IIS 中的应用程序池没有在您的本地帐户下运行(因此获得了不同的文件夹)。默认情况下,出于安全原因,IIS 使用特殊的受限帐户:iis.net/learn/manage/configuring-security/…

标签: c# wcf iis


【解决方案1】:

Kernel32.dll:GetTempPath() 的文档可能会对您有所帮助:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa364992(v=vs.85).aspx

基本上发生的情况是 IIS 在未定义 USERPROFILE 环境变量的帐户下运行,因此它使用 TMP 或 TEMP。

请记住,w3wp(IIS 中的工作进程)通常作为 DefaultAppPool 运行,而不是作为分配了目录的实际用户。

希望这会有所帮助!

【讨论】:

    【解决方案2】:
    //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();
    

    【讨论】:

    • 但是当前用户是什么?阅读 Kevin Gosse 的评论。
    猜你喜欢
    • 2013-10-08
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 2010-11-22
    • 2010-10-30
    相关资源
    最近更新 更多