3

The temporary directory that's used by ASP.NET is usually located under

C:\Windows\Microsoft.NET\Framework\<version>\Temporary ASP.NET Files\

Sometimes however it is overridden by the tempDirectory attribute on the compilation element in the web.config file.

How can I get the temporary directory currently used by ASP.NET regardless if it's the default directory or a user overridden directory?

P.S. There are a few properties that will return a subdirectory under the temporary directory (e.g. AppDomain.CurrentDomain.DynamicDirectory and others) but I'm looking for the directory as it appears in the configuration file.

James Couvares
  • 1,743
  • 1
  • 16
  • 15

1 Answers1

4

You want the static property HttpRuntime.CodegenDir

<%@ Page Language="C#" %>
<script runat="server" language="C#">
  void Page_Load(object Sender,EventArgs E)
  {

    lblCodegenDir.Text = System.Web.HttpRuntime.CodegenDir;
  }
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
  <HEAD>
    <TITLE>Test Application</TITLE>
  </HEAD>
  <BODY>
    <FORM id="frmForm1" method="post" runat="server">
      <HR width="100%" size="1">
      <P>
         ASP.Net Temp Dir:&nbsp;
        <ASP:LABEL id="lblCodegenDir" runat="server">Label</ASP:LABEL>
      </P>
      <HR width="100%" size="1">
    </FORM>
  </BODY>
</HTML>
Aristos
  • 66,005
  • 16
  • 114
  • 150
Christopher G. Lewis
  • 4,777
  • 1
  • 27
  • 46