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

编程入门 行业动态 更新时间:2024-10-23 17:26:26
本文介绍了HTTPContext .Current为空时如何使用Server.MapPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have some code that works fine when I need to delete some image files from a directory on my web server:

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

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

..but I am running into a problem when a maintenance task running in a separate thread at set intervals determines that files like the above need to be deleted:

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.

In this latter case, HttpContext.Current.Server.MapPath(ImageURL) has a value of Nothing.

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

Is there a way to get the full path for this case?

推荐答案

假定路径是相对的,则单独的进程不知道它们相对于哪个Web应用程序是相对的.在这种情况下,您将需要将其存储在配置中,或者将两者附加在一起,或者在〜/

Assuming that the paths are relative then the separate process does not know what they are relative to, which web application. In this case you will need to store it in the config and either append the two together or perform a string replace on ~/

更多推荐

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

本文发布于:2023-11-09 15:49:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572775.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   为空   Current   HTTPContext   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!