如何以编程方式获取 ASP.NET 临时目录?

发布于 2024-07-29 17:48:38 字数 323 浏览 1 评论 0原文

ASP.NET 使用的临时目录通常位于

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

“有时”下,但它会被 web.config 文件中的编译元素上的 tempDirectory 属性覆盖。

如何获取 ASP.NET 当前使用的临时目录,无论它是默认目录还是用户覆盖的目录?

PS 有一些属性将返回临时目录下的子目录(例如 AppDomain.CurrentDomain.DynamicDirectory 等),但我正在查找配置文件中显示的目录。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身情人 2024-08-05 17:48:38

您需要静态属性 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: 
        <ASP:LABEL id="lblCodegenDir" runat="server">Label</ASP:LABEL>
      </P>
      <HR width="100%" size="1">
    </FORM>
  </BODY>
</HTML>

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: 
        <ASP:LABEL id="lblCodegenDir" runat="server">Label</ASP:LABEL>
      </P>
      <HR width="100%" size="1">
    </FORM>
  </BODY>
</HTML>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文