使用 ServiceStack 为根路径“/"创建路由 [英] Create route for root path, '/', with ServiceStack
本文介绍了使用 ServiceStack 为根路径“/"创建路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为根目录/"设置 RestPath,但它不允许我这样做.它说 RestPath '/' on Type 'MainTasks' is not Valid
I'm trying to set a RestPath for root, '/', but its not allowing me to. Its saying RestPath '/' on Type 'MainTasks' is not Valid
有没有办法允许这样做?我想从根提供资源.
Is there a way to allow this? I'd like to provide a resource from the root.
[Route("/", "GET")]
public class MainTasks : IReturn<MainTasksResponse>
{
}
推荐答案
您只能在 / 路径上进行匹配rel="nofollow">ServiceStack 带有 FallbackRoute,例如:
You can only match on the Route /
Path in ServiceStack with a FallbackRoute, e.g:
[FallbackRoute("/{Path*}")]
public class Fallback
{
public string Path { get; set; }
}
这使用通配符来处理每个不匹配的路由(包括/foo/bar).只允许 1 个后备路线.
This uses a wildcard to handle every unmatched route (inc. /foo/bar). Only 1 fallback route is allowed.
还有其他一些方法可以处理默认的根路径/:
There are also a few other ways to handle the default root path /:
- 更改
EndpointHostConfig.DefaultRedirectPath
以重定向到您希望使用的服务 - 添加
default.cshtml
Razor 或 Markdown 视图或静态default.htm
(用于 HTML 请求) - 注册
EndpointHostConfig.RawHttpHandlers
- 这是在 ServiceStack 的操作顺序. - 注册一个
IAppHost.CatchAllHandlers
- 这会在 不匹配 请求时调用. - 在全局请求过滤器中处理请求立>
- Change the
EndpointHostConfig.DefaultRedirectPath
to redirect to the service you wish to use - Add a
default.cshtml
Razor or Markdown View or staticdefault.htm
(for HTML requests) - Register a
EndpointHostConfig.RawHttpHandlers
- This is the first handler looked at in ServiceStack's Order of Operations. - Register a
IAppHost.CatchAllHandlers
- This gets called for un-matched requests. - Handle the request in a Global Request Filter
这篇关于使用 ServiceStack 为根路径“/"创建路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文