Add extension to your Service stack response

First thing first:  SERVICESTACK IS VERY COOL

I had a case in my project to change the default extn of the response file (csv )to something else.

Thank God I was using Service Stack so I on the fly saved;)

 

Just add a Response filter and do what you wish todo .Add below code to your apphost.cs file

 

this.ResponseFilters.Add((req, res, dto) =>
            {
                if (req.ResponseContentType == ContentType.Csv)
                {
                    res.AddHeader(HttpHeaders.ContentDisposition,
                    string.Format("attachment;filename={0}.bin", req.OperationName+ Guid.NewGuid().ToString()));
                }
            });

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s