Create route for root path, '/', with ServiceStack

前端 未结 3 1714
后悔当初
后悔当初 2020-12-31 11:10

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 t

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 11:57

    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; }
    }
    

    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 /:

    1. Change the EndpointHostConfig.DefaultRedirectPath to redirect to the service you wish to use
    2. Add a default.cshtml Razor or Markdown View or static default.htm (for HTML requests)
    3. Register a EndpointHostConfig.RawHttpHandlers - This is the first handler looked at in ServiceStack's Order of Operations.
    4. Register a IAppHost.CatchAllHandlers - This gets called for un-matched requests.
    5. Handle the request in a Global Request Filter

提交回复
热议问题