更新时间:2023-12-02 15:09:34
ServiceStack 中没有保护/paths 的配置.
There is no configuration to protect /paths in ServiceStack.
您可以通过在任一操作上添加 [Authenticate]
属性来保护服务:
You can protect services by adding the [Authenticate]
attribute on either the Action:
class MyService : Service {
[Authenticate]
public object Get(Protected request) { ... }
}
请求 DTO
[Authenticate]
class Protected { ... }
或者服务实现
[Authenticate]
class MyService : Service {
public object Get(Protected request) { ... }
}
或者从基类继承
[Authenticate]
class MyServiceBase : Service { ... }
class MyService : MyServiceBase {
public object Get(Protected request) { ... }
}
否则,如果您可以使用全局请求过滤器,如果您想以任何其他方式限制所有请求,例如:
Otherwise if you can use a global Request Filter if you wanted to restrict all requests any other way, e.g something like:
appHost.RequestFilters.Add((httpReq, httpResp, requestDto) =>
{
if (IsAProtectedPath(httpReq.PathInfo)) {
new AuthenticateAttribute()
.Execute(httpReq, httpResp, requestDto);
}
});