Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 313 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get ASP.NET temporary folder path

#1
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?
Reply

#2
Much more safe will be if you use your own temporary folder in for example App_Data

Unfortunately `Path.GetTempPath(); ` won't return this folder because it is asp.net internal folder.

The good news is that you can change it specifing the file location in web.config with <compilation tempDirectory="directorylocation" /> element.
Reply

#3
I think this should help...

There is a section in `web.config/machine.config` under the `compilation tag` where the path is set by default. Here are the attributes of the section...

[Documentation here][1]


[1]:

[To see links please register here]

Reply

#4
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][1], and also relies on the [assumption][2] that default ASP.NET temporary folders are `hard-coded`.

Correct me, if you find a better way?


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#5
Try `System.Web.HttpRuntime.CodegenDir` to get the physical path of directory where the ASP.NET temporary files are stored for the current application.
Reply

#6
Simplest way with validation:

if (file.ContentLength > 0)
{
string temp = Path.GetTempPath();

var path = Path.Combine(temp, fileName);
file.SaveAs(path);
}

and in web.config:

<system.web>
<compilation tempDirectory="D:\MyTempFiles" />
</system.web>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through