使用 Asp.Net 获取服务器上 Web 应用程序文件夹之外的数据库路径
我向服务器发布了一个 Web 应用程序,我想访问一个数据库文件 (.mdb),该文件也存储在服务器上与我的服务器不同的位置。如何在我的 Asp.Net 应用程序的 web.config 文件中执行此操作?
<add name="MyOleDbConnection" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source= **{?}** \inventory.mdb"/>
I published a web app to a server and I would like to access a database file (.mdb) that is also stored on the server in a different location outside of mine. How can I do this in the web.config file of my Asp.Net app?
<add name="MyOleDbConnection" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source= **{?}** \inventory.mdb"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不相信你可以通过代码,使用诸如 Server.MapPath() 之类的东西来做到这一点 - 并且有充分的理由。这将允许开发人员编写接管云服务器上主机操作系统的应用程序。您无法确定 IIS 控制之外的文件/文件夹的路径,以防止目录遍历攻击。
您需要询问系统管理员或有权访问该计算机上的路径的人员。获得完整路径后,您可以在 .config 中设置完整路径,
而不是
您还需要确保系统管理员授予您访问 .mdb 的权限。
I don't believe you can do it from code, using anything like Server.MapPath() - and for good reason. This would allow developers to write apps that take over host operating systems on cloud servers. You're restricted from determining the path of files/folders outside of the control of IIS to prevent directory traversal attacks.
You'll need to ask a SysAdmin, or someone who has access what the path is on that machine. Once you have the full path, you can set the full path in the .config
instead of
You will also need to make sure that the SysAdmin grants you permissions to access the .mdb.