使用 servicestack 提供静态文件 [英] Serving a static file with servicestack
问题描述
我将如何使用 servicestack 处理静态文件?
How would i go around serving a static file using servicestack?
我想添加一个像 Routes.Add(/app) 这样的路由,当客户端为这条路径发出 GET 请求时,我需要返回一个 Silverlight xap 文件.
I would like to add a route like Routes.Add(/app) and when a client issues a GET for this path i need to return the a silverlight xap file.
推荐答案
ServiceStack 已经能够通过直接引用静态文件来提供它们.
ServiceStack is already be able to serve static files by referencing them directly.
否则,如果您希望服务返回文件以供下载,您可以这样做:
Otherwise if you want a service return a file for downloading, you can do so with:
return new HttpResult(new FileInfo("~/app.xap"), asAttachment:true) {
ContentType = "application/x-silverlight-app"
};
注意:asAttachment
将控制是否发送 HTTP Content-Disposition
标头.
Note: asAttachment
will control whether or not to send HTTP Content-Disposition
headers.
有关 ServiceStack 响应的更多信息在此较早的问题中:ServiceStack 并返回流
More info about ServiceStack's responses is in this earlier question: ServiceStack and returning a stream
这篇关于使用 servicestack 提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!