Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ASP.NET temporary folder path

Tags:

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\Temporary ASP.NET Files

I'd hate to hard-code this path into my code, so I was wondering if I can retrieve it from .NET framework itself?

like image 577
c00000fd Avatar asked Oct 02 '13 04:10

c00000fd


People also ask

What is path GetTempPath ()?

Path GetTempPath Returns the path of the current user's temporary folder.

What is a ASP.NET folder?

Below is a typical folder structure for an ASP.NET web pages web site: The "Account" folder contains logon and security files. The "App_Data" folder contains databases and data files. The "Images" folder contains images. The "Scripts" folder contains browser scripts.


1 Answers

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"); 

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?

like image 148
c00000fd Avatar answered Oct 05 '22 02:10

c00000fd