【问题标题】:Use Asp.Net Web API to download file from sharing folders使用 Asp.Net Web API 从共享文件夹下载文件
【发布时间】:2014-04-10 10:01:02
【问题描述】:

我有一个 FileManagement(FM) 站点和多个 IIS。在每个 IIS 上,我存储了一些文件,所有这些文件都在共享文件夹下。我需要为客户端创建一个API,当客户端传递服务器地址,物理路径时,FM将从指定的IIS下载文件并返回给客户端。

这是一个放在 IIS A 上的路径文件 Menu.txt:

App_Data\Store\Menu.txt。 App_Data 是共享文件夹,名称为:\SERVER-AppData。

当我将参数传递给 API 时,它将是这样的:

服务器地址:IISA的IP地址

路径:\SERVER-AppData\Store\Menu.txt

我使用 WebClient 在 Test API 项目中下载。

// Create a new WebClient instance
WebClient myWebClient = new WebClient();
myWebClient.Credentials = new System.Net.NetworkCredential("username", "password", "domain");

// Concatenate the domain with the Web resource filename.
string myStringWebResource = Path.Combine(serverAddress, path);
string store = @"E:\file.txt";

// Download the Web resource and save it into the current filesystem folder.
byte[] bytes = myWebClient.DownloadData(myStringWebResource);

当我运行它时,它说:用户名或密码错误。但在 Window Explorer 的 Network 中。我使用正确的用户名和密码连接到该服务器。

【问题讨论】:

    标签: c# asp.net-mvc asp.net-web-api


    【解决方案1】:

    将文件存储在数据库中而不是物理文件中。

    然后您可以从任何连接的 IIS 机器下载。

    【讨论】:

    • 我无法将文件存储在数据库中,文件存储在每个 IIS 上
    猜你喜欢
    • 2019-08-06
    • 2020-01-09
    • 1970-01-01
    • 1970-01-01
    • 2014-09-15
    • 1970-01-01
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    相关资源
    最近更新 更多