简体   繁体   English

ServiceStack中基于会话的验证

[英]Session based validation in ServiceStack

I have some validation logic, which is based a user's session. 我有一些验证逻辑,它基于用户的会话。 Сan I access the session from a class inherited from AbstractValidator? Сan我从继承自AbstractValidator的类访问会话?

Or is there another way to check RequestDTO based session? 或者是否有另一种方法来检查基于RequestDTO的会话?

For example I can use filters for that (and I can access the session via IRequest parameter req in overrided Execute method), but I don't know how to return the response from the class of the filter, bypassing the main method of the operation. 例如,我可以使用过滤器(我可以通过覆盖的Execute方法中的IRequest参数req访问会话),但我不知道如何从过滤器的类返回响应,绕过操作的主要方法。 If I will throw the Exception, the service will not work properly because RequestDTO declared outside of my project and it is not inherited from IReturn<> and does not contain a ResponseStatus field. 如果我将抛出异常,该服务将无法正常工作,因为RequestDTO在我的项目之外声明并且它不是从IReturn <>继承而且不包含ResponseStatus字段。

Thanks in advance for any help (and sorry for my English) 在此先感谢您的帮助(对不起我的英语)

If your validator implements IRequiresRequest then it will injected with the current IRequest which you can use in your lambda expressions, eg: 如果您的验证器实现了IRequiresRequest那么它将注入您可以在lambda表达式中使用的当前IRequest ,例如:

public class CustomValidator : AbstractValidator<Request>, IRequiresRequest 
{
    public IRequest Request { get; set; }
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM