我正在做一个小项目,它使用位于WPF应用程序中的Nancy。我希望能够远程下载一个PDF文件,即~8MB。我能够让下载工作,但当下载正在进行时,应用程序将不会响应任何其他请求。是否有一种方法可以允许文件下载而不绑定所有其他请求?
Public Class ManualsModule : Inherits NancyModule
Public Sub New()
MyBase.New("/Manuals")
Me.Get("/") = Function(p)
Dim model As New List(Of String) From {"electrical", "opmaint", "parts"}
Return View("Manuals", model)
End Function
Me.Get("/{name}") = Function(p)
Dim manualName = p.name
Dim fileResponse As New GenericFileResponse(String.Format("Content\Manuals\{0}.pdf", manualName))
Return fileResponse
End Function
End Sub
End Class或在C#中
public class ManualsModule : NancyModule
{
public ManualsModule() : base("/Manuals")
{
this.Get("/") = p =>
{
List<string> model = new List<string> {
"electrical",
"opmaint",
"parts"
};
return View("Manuals", model);
};
this.Get("/{name}") = p =>
{
dynamic manualName = p.name;
GenericFileResponse fileResponse = new GenericFileResponse(string.Format("Content\\Manuals\\{0}.pdf", manualName));
return fileResponse;
};
}
}发布于 2013-11-21 19:24:50
我发现我实际上是在WCF主持南希,而不是自己主持。我描述的行为只有在WCF中托管时才会发生。自我主机在我的应用程序中会很好,所以我会同意的。
发布于 2015-09-08 19:28:01
var file = new FileStream(zipPath, FileMode.Open);
string fileName = //set a filename
var response = new StreamResponse(() => file, MimeTypes.GetMimeType(fileName));
return response.AsAttachment(fileName);发布于 2017-05-04 05:00:13
最简单的方法是围绕它创建一个StreamWriter,如下所示:
var response = new Response();
response.Headers.Add("Content-Disposition", "attachment; filename=test.txt");
response.ContentType = "text/plain";
response.Contents = stream => {
using (var writer = new StreamWriter(stream))
{
writer.Write("Hello");
}
};
return response;https://stackoverflow.com/questions/20121730
复制相似问题