4

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.

Johnny
  • 313
  • 1
  • 5
  • 10

1 Answers1

6

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

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thanks, it's really that easy :-) I never thought of refereeing to the files directly with servicestack. – Johnny Aug 26 '12 at 13:59
  • What does "referencing a file directly" mean? What is an example of referencing a file directly from ServiceStack? – jimjim Apr 22 '13 at 00:45
  • 2
    @Arjang you just reference the static file as you would in MVC or ASP.NET e.g. `http://localhost/example.html` will automatically serve the `~/example.html` file in you WebRoot if it exists. If you're self-hosting servicestack (i.e. using HttpListener and not ASP.NET) you need to set the **Build Action** of each static file you want to serve with **Copy If Newer** so a copy is added to the `/bin` directory which the self HttpListener host can access. – mythz Apr 22 '13 at 00:51