Serving a static file with servicestack

2019-05-07 00:48发布

问题:

How would i go around serving a static file using servicestack?

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.

回答1:

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"
};

Note: asAttachment will control whether or not to send HTTP Content-Disposition headers.

More info about ServiceStack's responses is in this earlier question: ServiceStack and returning a stream