ASP .net 当前物理位置

发布于 2024-08-11 05:50:46 字数 556 浏览 2 评论 0原文

您好,我正在开发 ASP.net Web 应用程序。 我需要找到网站的当前位置(物理位置)(或包含程序集的 bin 目录)。

我尝试使用 Directory.GetCurrentDirectory() 并返回 ASP .net 临时目录。

我真的不喜欢在我的配置文件中包含绝对路径的应用程序设置的想法(eww!)

任何帮助将不胜感激! :)

结论:

我应该给出一些上下文来说明为什么我需要物理文件路径。 感谢大家对问题的及时答复:)

我正在使用 XSL-FO for .net (FO.net 库)生成 PDF。在 FO 中嵌入图像需要给出绝对路径:

<fo:external-graphic src="C:\MyWebsite\images\image1.jpg" />

我需要做的是将当前目录设置为网站(或 bin 目录),这将使 XSL FO 渲染器知道在哪里可以找到图像。

Hi I am developing an ASP.net web application.
I need to find the current location (physical) of the web site (or the bin directory containing the assemblies).

I have tried using Directory.GetCurrentDirectory() and that returns me the ASP .net temporary directory.

I really don't like the idea of include an application setting for the absolute path in my config file (eww!)

Any help would be much appreciated! :)

Conclusion:

I should have given some context as to Why I would like the physical file path.
Thanks guys for your prompt responses to the question :)

I am using XSL-FO for .net (the FO.net library) to generate a PDF. Embedding images in FO requires an absolute path to be given:

<fo:external-graphic src="C:\MyWebsite\images\image1.jpg" />

What I needed to do was set the current directory to the web site (or bin directory), which would allow the XSL FO renderer to know where to find the image.

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

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

发布评论

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

评论(2

提笔书几行 2024-08-18 05:50:46

您需要 System.Web.HttpRuntime.BinDirectory(bin 文件夹的物理路径)和 System.Web.HttpRuntime.AppDomainAppPathbin 文件夹的物理路径)顶级 ASP.NET 应用程序文件夹)。

You need System.Web.HttpRuntime.BinDirectory (physical path to the bin folder) and System.Web.HttpRuntime.AppDomainAppPath (physical path to the top-level ASP.NET application folder).

我也只是我 2024-08-18 05:50:46

这取决于您想要对路径执行的操作,但通常的方法是 Server.MapPath()。例如:

YourControl.src = Server.MapPath("~/images/image1.jpg");

这将返回指定文件的物理路径。

It depends on exactly what you want to do with the path, but the usual approach is Server.MapPath(). For example:

YourControl.src = Server.MapPath("~/images/image1.jpg");

That will return the physical path for the specified file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文