映射 IIS 外部的服务器路径

发布于 2024-07-15 10:05:23 字数 378 浏览 5 评论 0原文

我有一个网络应用程序,用户可以在其中上传文件。 这些文件由 IIS 物理存储在映射到外部存储设备的虚拟文件夹中。 有关每个上传文件的记录存储在数据库中。 数据库记录包含有关文件是否仍然“活动”(尚未被用户删除)以及虚拟文件夹路径(例如:/storage1/test)的信息。

现在,我想定期运行管理IIS 外部的任务,检索不再“活动”的所有文件的列表,并从物理存储中删除这些文件。 我希望管理任务作为计划任务或 Windows 服务在 IIS 外部运行。 但是,我无法弄清楚如何在外部进程中将存储在数据库记录中的虚拟文件夹路径映射到物理路径。 有什么方法可以从外部进程“接入”IIS 或任何其他智能方法来执行此操作吗? (或者我完全走错方向了)。

TIA /亨里克

I have a web app where users can upload files. The files are physically stored by IIS in a virtual folder that is mapped to an external storage device.
A record about each uploaded file is stored in the database. The database record contains information about whether the file is still "active" (hasn't been deleted by the user), and the virtual folder path (ex: /storage1/test)

Now, I would like to, periodically, run an administrative task outside IIS that retrieves a list of all files that are no longer "active" and deletes these from physical storage.
I would like the administrative task to run outside IIS as a scheduled task or windows service.
However, I cannot figure out how to map the virtual folder path that stored in the database record to a physical path, in the external process. Is there any way to "tap" into IIS from an external process or any other smart way to do this? (or am I going in the wrong direction altogether).

TIA
/Henrik

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

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

发布评论

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

评论(3

好多鱼好多余 2024-07-22 10:05:23

您需要在项目中添加对 System.Web 的引用。

string path = System.Web.HttpServerUtility.MapPath("/MyWebSite");

You'll need to add a reference to System.Web in your project.

string path = System.Web.HttpServerUtility.MapPath("/MyWebSite");
清醇 2024-07-22 10:05:23

如果您的应用程序是 ASP.NET 应用程序,您可以研究 Server.MapPath 调用 - 如果您使用与主应用程序相同的虚拟目录。

否则,我建议将“基本路径”(对应于虚拟目录路径)存储在外部应用程序的配置中,然后将该基本路径和文件路径连接成完整路径。

马克

If your app is an ASP.NET app, you could investigate the Server.MapPath call - if you're using the same virtual directory as the main app.

Otherwise, I'd suggest storing the "base path" (that corresponds to the virtual directory path) in a config for your external app and just concatenating that base path and the file path into a complete path.

Marc

清君侧 2024-07-22 10:05:23

如果您需要以编程方式检索此路径,那么您可以执行以下操作:

using(DirectoryEntry de = 
    new DirectoryEntry("IIS://Localhost/w3svc/1/root/storage1/test"))
{
    string pathToFiles = de.Properties["Path"].Value;

    // Do my file tidy up tasks....
}

有几件事需要注意:

  • 路径中的数字“1
    DirectoryEntry 构造函数是
    站点的 IIS 编号。

  • 在路径中
    IIS://Localhost/w3svc/1/root/storage1/test,
    第一部分
    IIS://Localhost/w3svc/1/root
    您网站的“根”应用程序。
    你总是需要这部分。

  • 您需要添加对
    System.DirectoryServices
    程序集到您的项目中。

If you need to retrieve this path programmatically then you can do something like:

using(DirectoryEntry de = 
    new DirectoryEntry("IIS://Localhost/w3svc/1/root/storage1/test"))
{
    string pathToFiles = de.Properties["Path"].Value;

    // Do my file tidy up tasks....
}

There are a couple of things to note:

  • The number '1' in the path of the
    DirectoryEntry constructor is the
    IIS number of the site.

  • In the path
    IIS://Localhost/w3svc/1/root/storage1/test,
    the first part
    IIS://Localhost/w3svc/1/root is
    your website's 'root' application.
    You always need this part.

  • You would need to add a reference to
    the System.DirectoryServices
    assembly to your project.

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