获取ASP.NET临时文件夹路径 [英] Get ASP.NET temporary folder path
问题描述
在不是从IIS / ASP.NET内部运行的C#代码中,我需要向ASP.NET临时文件夹添加用户帐户权限。 (将我的网站添加到IIS时是必需的。)我的本地系统上的文件夹是:
From my C# code, that doesn't run from within IIS/ASP.NET, I need to add a user account permissions to the ASP.NET temp folder. (It is required while adding my site to IIS.) The folder on my local system is:
C:\Windows\Microsoft .NET\Framework64\v4.0.30319\ASP.NET临时文件
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
我不愿硬编码此路径进入我的代码,所以我想知道是否可以从.NET框架本身中检索它?
I'd hate to hard-code this path into my code, so I was wondering if I can retrieve it from .NET framework itself?
推荐答案
Hmm。我不知道会这么复杂。由于缺少更好的答案,我能够想到这样的东西:
Hmm. I didn't know that it would be so complicated. For the lack of better answer, I was able to come up with something like this:
using System.Runtime.InteropServices;
string net_base = Path.GetFullPath(Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), @"..\.."));
string strTemp32 = string.Concat(net_base, @"\Framework\", RuntimeEnvironment.GetSystemVersion(), @"\Temporary ASP.NET Files");
string strTemp64 = string.Concat(net_base, @"\Framework64\", RuntimeEnvironment.GetSystemVersion(), @"\Temporary ASP.NET Files");
显然有两个临时文件夹-用于32位和64位进程。它基于此示例,并且还依赖于假设,默认的ASP.NET临时文件夹是硬编码的
。
There're obviously two temp folders -- for 32-bit and 64-bit processes. It is based on this sample, and also relies on the assumption that default ASP.NET temporary folders are hard-coded
.
纠正我,如果您找到更好的方法?
Correct me, if you find a better way?
这篇关于获取ASP.NET临时文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!