使用Microsoft IIS创建下载链接 [英] Create a download link with Microsoft IIS

查看:39
本文介绍了使用Microsoft IIS创建下载链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Microsoft IIS设置直接下载链接.我们已经有一个使用IP地址的网页指向我们服务器上的/web文件夹,但是我想在服务器上创建一个单独的位置,可以在该位置放置可下载的文件,以便客户端可以只键入链接并获取下载:http://IPADDR/download/filename.zip.是否有任何有关执行此操作的资源?

I want to set up a direct download link using Microsoft IIS. We already have a web page using the IP address that points to a /web folder on our server, but I want to create a separate location on my server where I can put downloadable files such that the client can just type the link and get the download: http://IPADDR/download/filename.zip. Are there any resources on how to do this?

现在,键入http://IPADDR会打开我们的简单网页,其中包含一个可启动应用程序的链接,这又是通过IIS绑定到我们服务器上的/web文件夹的.

Right now, typing http://IPADDR brings up our simple web page which contains a link that launches an application, again this is bound to the /web folder on our server via IIS.

FTP端口通常在客户端的网络上被阻止,因此我们必须坚持使用HTTP.这将完全是程序性的,因此无需在页面上具有按钮或链接.我将使用带有GET命令的Java从链接中提取文件.我只希望能够使Web服务器使这些文件可供下载.

The FTP port is typically blocked on our client's networks so we have to stick with HTTP. This will be completely programmatic, so no need to have a button or link on a page. I will be using java with a GET command to pull files from the link. I just want to be able to have the web server make these files available to download.

仅供参考,我对此服务器产品比较新,所以越简单越好!谢谢.

FYI I'm newer to this server stuff so simpler is better! Thank you.

推荐答案

据我所知,有两种方法可以满足您的需求.

As far as I know, there are two ways to achieve your needs.

第一个是使用Asp.net应用程序.您需要为下载的文件编写代码.例如,当用户单击一个按钮时,将触发与该按钮相对应的逻辑方法,并且对客户端的响应就是代码中指定的文件.

The first is using Asp.net application. You need to write code for the downloaded file. For example, when the user clicks a button, the logic method corresponding to the button is triggered, and the response to the client is the file specified in the code.

        var fileNameToShow = "xxx.zip";
        var fileNameAndPath = "The physical path of the file on the server"
        FileInfo file = new FileInfo(fileNameAndPath);
        file.Refresh();
        if (file.Exists)
        {
            // Send the file to the browser
            Response.Clear();
            Response.AddHeader("Content-Disposition",
                "attachment; filename= " + fileNameToShow + "; size=" + file.Length.ToString());
            Response.TransmitFile(fileNameAndPath);
            Response.Flush();
            Response.End();
        }
        else
        {
            throw new Exception("File does not exist!");
        }

第二个是使用IIS的FTP功能.您需要创建一个站点并将FTP发布添加到该站点.通过ftp://domian访问该站点时,您可以在服务器上该站点的物理目录中看到所有文件,并且可以通过单击下载任何文件.(也可以通过链接下载,例如ftp://domain/filename.zip)

The second is to use the FTP function of IIS. You need to create a site and add FTP publishing to the site. When you visit the site through ftp://domian, you can see all the files in the physical directory of the site on the server, and you can download any file by clicking on it.(It also can download through link,such as ftp://domain/filename.zip)

这篇关于使用Microsoft IIS创建下载链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆