在 ASP.NET 中,当 HttpContext.Current 为 NULL 时如何获取物理文件路径?

发布于 2024-07-06 11:46:35 字数 121 浏览 13 评论 0原文

我正在使用 DotNetNuke 的调度程序来安排任务,并且希望获取我创建的电子邮件模板的物理文件路径。 问题是HttpContext为NULL,因为计划任务在不同的线程上并且没有http请求。 您将如何获取文件的物理路径?

I'm working with DotNetNuke's scheduler to schedule tasks and I'm looking to get the physical file path of a email template that I created. The problem is that HttpContext is NULL because the scheduled task is on a different thread and there is not http request. How would you go about getting the file's physical path?

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

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

发布评论

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

评论(5

椒妓 2024-07-13 11:46:35

有很多方法可以做到这一点,我个人通过将路径信息存储为模块的配置选项来解决这个问题,它并不优雅,但它每次都有效。

Joe Brinkman 我相信附近有一篇博客文章介绍了如何构建一个新的 HTTPContext 以在调度程序中使用。

There are many ways of doing this, I personally get around it by storing path information as a config option for my modules, it isn't elegant, but it works and works every time.

Joe Brinkman I belive somewhere around has a blog posting on how to construct a new HTTPContext for use inside the scheduler.

紫南 2024-07-13 11:46:35

由于此过程实际上是与网站相关的带外过程,因此也许您可以将路径放入配置文件中。

可能不是最好的主意,但它是一个替代方案。

Since this process is really out-of-band in relation to the web site, maybe you can just put the path in a config file.

May not be the best idea, but it is an alternative.

萌酱 2024-07-13 11:46:35

this.GetType().Assembly.Location 说什么?

what says this.GetType().Assembly.Location ?

孤君无依 2024-07-13 11:46:35

你能看看大会和会议吗? 像这样的代码库路径:

Imports System.Reflection
Imports System.IO
...
Path.GetDirectoryName( Assembly.GetExecutingAssembly().CodeBase ) 

这种东西并不总是有效,所以我建议做的是编写一个包含大量有关程序集的数据的日志,以查看该位置的工作原理。 当我创建要在 AppCenter 中托管的 COM 组件时,我必须这样做才能获得类似的东西。 我用它来“获取”“APP_BASE”应该是什么,并设置它,以便 app.config 文件能够正确加载。

Log.Write ( Assembly.GetExecutingAssembly().CodeBase )
Log.Write ( Assembly.GetExecutingAssembly().Location )
Log.Write ( Path.GetFullPath(".") )
Log.Write ( Application.StartupPath )
... and so on, whatever you can think of ...

Can you look at the Assembly & the CodeBase paths like this:

Imports System.Reflection
Imports System.IO
...
Path.GetDirectoryName( Assembly.GetExecutingAssembly().CodeBase ) 

That kind of stuff doesn't always work, so what I would recommend doing is writing a log with a bunch of data about the assembly, to see what works in this location. It is what I had to do to get something similar when I was creating a COM component to be hosted in AppCenter. I used this to "get" what "APP_BASE" should be, and set that, so the app.config file would load properly.

Log.Write ( Assembly.GetExecutingAssembly().CodeBase )
Log.Write ( Assembly.GetExecutingAssembly().Location )
Log.Write ( Path.GetFullPath(".") )
Log.Write ( Application.StartupPath )
... and so on, whatever you can think of ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文