Pergunta

I am trying to customize the visibility of a ServiceStack endpoint using the Restrict attribute like so.

[Route("/test", Verbs = "GET")]
[Restrict(VisibilityTo = RequestAttributes.Localhost)]
public class TestDto
{
  ...
}

However this is causing the API to be invisible from both localhost and externally. I am getting the same behavior with LocalSubnet. All of the formats on the metadata page are grayed out and I don't see the route in Swagger when browsing from localhost.

Foi útil?

Solução

This is happening is because you haven't defined the formats that this restriction applies to. The metadata page is indicating this by not showing any formats available. You can specify the formats like so.

[Restrict(VisibilityTo = RequestAttributes.Localhost | RequestAttributes.Xml | RequestAttributes.Json)]

This will show the route on localhost requests for json and xml formats. To get the route visible in Swagger, you must allow Json.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top