Set temporary folder for web application with impersonation as HttpRuntime.CodegenDir?

M

Mathieu Cartoixa

Hi all,

We have developed a web application in ASP .NET (C#, .NET 2.0, IIS 6.0,
Windows Server 2003), with integrated Windows authentification, and
impersonation. I have tried to use memory streams, as opposed to
temporary files, as often as possible beacuse we want to spare our
client the pain of folder rights administration.
But our efforts proved worthless as we integrated Crystal Reports
(VS2005 edition) in our application : their framework relies on the
creation of such temporary files, in C:\WINDOWS\Temp and in
....\ASPNET\Local Settings\Temp (%TMP%, Crystal not always running under
impersonation).
To keep our goal, we managed to find what appears to be a good
solution, but about which we would like to get some feedback. In
Global.asax, we set :

void Application_Start(object sender, EventArgs e)
{
string tmpPath=HttpRuntime.CodegenDir;
WebUtilities.SetEnvironmentVariable("TMP", tmpPath);
WebUtilities.SetEnvironmentVariable("TEMP", tmpPath);
}

SetEnvironmentVariable is defined as :

public static class WebUtilities
{
[DllImport("kernel32.dll", EntryPoint="SetEnvironmentVariableW",
CharSet=CharSet.Unicode)]
public static extern bool SetEnvironmentVariable(string name,
string val);
}

Everything works fine, as far as we could test. Do you think we can
rely on this ?

Thanks in advance.

Mathieu CARTOIXA
 
M

Mathieu Cartoixa

Mathieu Cartoixa a écrit :
Hi all,

We have developed a web application in ASP .NET (C#, .NET 2.0, IIS
6.0, Windows Server 2003), with integrated Windows authentification, and
impersonation. I have tried to use memory streams, as opposed to
temporary files, as often as possible beacuse we want to spare our
client the pain of folder rights administration.
But our efforts proved worthless as we integrated Crystal Reports
(VS2005 edition) in our application : their framework relies on the
creation of such temporary files, in C:\WINDOWS\Temp and in
...\ASPNET\Local Settings\Temp (%TMP%, Crystal not always running under
impersonation).
To keep our goal, we managed to find what appears to be a good
solution, but about which we would like to get some feedback. In
Global.asax, we set :

void Application_Start(object sender, EventArgs e)
{
string tmpPath=HttpRuntime.CodegenDir;
WebUtilities.SetEnvironmentVariable("TMP", tmpPath);
WebUtilities.SetEnvironmentVariable("TEMP", tmpPath);
}

SetEnvironmentVariable is defined as :

public static class WebUtilities
{
[DllImport("kernel32.dll", EntryPoint="SetEnvironmentVariableW",
CharSet=CharSet.Unicode)]
public static extern bool SetEnvironmentVariable(string name, string
val);
}

Everything works fine, as far as we could test. Do you think we can
rely on this ?

OK, it seems that at some point you cannot avoid a bit of
administration when impersonating, even for this directory, cf.
http://msdn2.microsoft.com/en-us/library/kwzs111e.aspx

Mathieu CARTOIXA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top