从根投掷例外ServiceStack REST API路径变量 [英] ServiceStack REST API path variables from root throwing exception
问题描述
我想写使用ServiceStack接受了路线的变量路径REST Web服务。例如:
I am trying to write a REST web service using ServiceStack that accepts variable paths off of route. For example:
[Route("/{group}"]
public class Entity : IReturn<SomeType> {}
这将引发NotSupported异常RestPath'/ {}集合的实体类型不支持。但是,如果我更改路径如下(与APPHOST配置相关的路径)复制到:
This throws a NotSupported Exception "RestPath '/{collection}' on type Entity is not supported". However, if I change the path as follows (along with the associated path in AppHost configuration) to:
[Route("/rest/{group}"]
它工作得很好。为了与我一起工作的系统进行集成,我需要使用/ {}组。
It works just fine. In order to integrate with the system that I am working with, I need to use /{group}.
推荐答案
ServiceStack现在允许您添加的备用路线从 /
根路径来处理任何未匹配的要求,这是不是一个包罗万象的处理程序处理或指现有的静态文件。因此,在v3.9.56,你现在可以做的:
ServiceStack now allows you to add a fallback route from the /
root path to handle any un-matched requests, that's not handled by a catch-all handler or refers to an existing static file. So in v3.9.56 you can now do:
[FallbackRoute("/{group}"]
public class Entity : IReturn<SomeType> {}
另外一种方式是注册一个 IAppHost.CatchAllHandlers
来处理未匹配的路由,但是你需要回到自己的的IHttpHandler
来处理请求或可选择地返回一个 RedirectHttpHandler
来重定向到由ServiceStack管理不同的路线。
An alternative option is to register a IAppHost.CatchAllHandlers
to handle un-matched routes, but you would need to return your own IHttpHandler
to handle the request or alternatively return a RedirectHttpHandler
to redirect to a different route that is managed by ServiceStack.
这篇关于从根投掷例外ServiceStack REST API路径变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!