asp.net - HTTPContext .Current为空时如何使用Server.MapPath

标签 asp.net vb.net httpcontext server.mappath

当我需要从Web服务器上的目录中删除一些图像文件时,我有一些可以正常工作的代码:

Dim ImageURL As String = dsImages.Tables(0).Rows(iImgRow).Item("ImageURL")
Dim physicalName = Server.MapPath(ImageURL)
oUpload.DeleteFileFromServer(physicalName, iAdid, iImgID)


..但是当在单独的线程中以设置的时间间隔运行的维护任务确定需要删除上述文件时,我遇到了问题:

Dim ImageURL As String = dsImage.Tables(0).Rows(i - 1).Item("ImageURL")
Dim iImgID As Integer = dsImage.Tables(0).Rows(i - 1).Item("ImageId")
Dim physicalName As String = HttpContext.Current.Server.MapPath(ImageURL)
oUpload.DeleteFileFromServer(physicalName, iAdID, iImgID)


在后一种情况下,HttpContext.Current.Server.MapPath(ImageURL)的值为Nothing。

有没有办法获得这种情况的完整路径?

最佳答案

假设路径是相对的,则单独的进程将不知道它们与哪个Web应用程序相对。在这种情况下,您将需要将其存储在配置中,然后将两者附加在一起或在〜/上执行字符串替换

关于asp.net - HTTPContext .Current为空时如何使用Server.MapPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4742257/

相关文章:

asp.net - SQL删除花费太长时间

sql - 错误 - 附加信息 : Format of the initialization string does not conform to specification starting at index 0

vb.net - 代码编辑器 Visual Studio 2013 中的绿色带意味着什么?

.net - <Out()>属性。服务的目的是什么?

sql - SSIS-脚本组件,将单行拆分为多行(父子变量)

c# - 在旧版 ASP.NET 应用程序中进行单元测试以模拟 HttpContext

.net - 有没有办法确定客户端是否收到 .NET 中的 HTTP 响应?

c# - 发布错误 : Could not load file or assembly 'Microsoft.Web.XmlTransform' , Version=1.4.0.0, Culture=neutral 等或其依赖项之一

asp.net - WebApi.OwinSelfHost 是否足以在没有 IIS 的情况下运行 asp.net mvc 应用程序?

c# - 为什么我的 HttpApplication 实例变量为空?