使用 ServiceStack 为根路径“/"创建路由

编程入门 行业动态 更新时间:2024-10-14 20:26:20
本文介绍了使用 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 static default.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 为根路径“/"创建路由

    本文发布于:2023-11-24 12:41:29,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1625242.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:路由   路径   ServiceStack   quot

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!