0

I faced a problem with passing filename including extension to Service Stack method. Here is what I want to achieve:

[Route("/files/{FileName}")]
public class GetFile : IReturn<Stream>
{ 
   public string FileName { get; set; }
}

As a FileName I need to pass something like "SomeFile.extension". I tried

[Route("/files/{FileName}.{Extension}")]
public class GetFile : IReturn<Stream>
{ 
   public string FileName { get; set; }
   public string Extension { get; set; }
}

with no luck also. As a response I get

HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Does anyone know how to allow file extensions in Service Stack routes?

Thank you in advance.

  • This should work unless you already have a folder called `/files`? in which case it will attempt to return the physical file in the folder. – mythz Nov 27 '14 at 16:12

2 Answers2

2

Actually the solution was to add handler

<httpHandlers>
  <add verb="*" path="*.*" type="App.Handlers.SomeHandler" />
</httpHandlers>

and rewrite URL there

string url = Request.RawUrl.Replace(".", "%2E");
context.RewritePath(url);
1

You may be hitting the Content Negotiation feature in ServiceStack, which is a way to specify format with a .extension

https://github.com/ServiceStack/ServiceStack/wiki/Routing#content-negotiation

You can disable by setting:

Config.AllowRouteContentTypeExtensions = false

If that doesn't work, you can review issues with dots in routing

Community
  • 1
  • 1
Raul Nohea Goodness
  • 2,549
  • 23
  • 24
  • For some reason changing that property makes no effect. And I can't change response format by specifying ".json" or ".xml" in the end of URL (while "?format=xml" and "?format=json" work). – Denys Ubizskyy Nov 28 '14 at 13:03