加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 当HTTPContext .Current为Nothing时如何使用Server.M

发布时间:2020-12-15 20:23:05 所属栏目:asp.Net 来源:网络整理
导读:当我需要从Web服务器上的目录中删除一些图像文件时,我有一些代码可以正常工作: Dim ImageURL As String = dsImages.Tables(0).Rows(iImgRow).Item("ImageURL")Dim physicalName = Server.MapPath(ImageURL)oUpload.DeleteFileFromServer(physicalName,iAdid
当我需要从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应用程序.在这种情况下,您将需要将其存储在配置中,并将两者附加在一起,或在?/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读