映射 IIS 外部的服务器路径
我有一个网络应用程序,用户可以在其中上传文件。 这些文件由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在项目中添加对 System.Web 的引用。
You'll need to add a reference to System.Web in your project.
如果您的应用程序是 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
如果您需要以编程方式检索此路径,那么您可以执行以下操作:
有几件事需要注意:
路径中的数字“
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:
There are a couple of things to note:
The number '
1
' in the path of theDirectoryEntry
constructor is theIIS number of the site.
In the path
IIS://Localhost/w3svc/1/root/storage1/test
,the first part
IIS://Localhost/w3svc/1/root
isyour website's 'root' application.
You always need this part.
You would need to add a reference to
the
System.DirectoryServices
assembly to your project.