2014-05-24 75 views
1

我知道我在某个时候碰到了一篇文章,但似乎找不到任何东西。看起来,默认情况下,ServiceStack允许通过GET或POST访问/ auth。 GET不是我们想要的产品。关闭GET访问ServiceStack自定义凭证提供程序

我需要关闭对/ auth的GET访问。有任何想法吗?

回答

3

您可以使用自定义AuthenticateServices到ValidateFn添加自定义的验证,如:

AuthenticateService.ValidateFn = (authService, verb, requestDto) => { 
    if (verb == HttpMethods.Get) 
     throw new NotSupportedException("GET's not allowed"); 
}; 

否则,您可以使用流利的API动态地添加属性对你没有自己的服务添加自己的Restricting Services Attributes ,例如:

typeof(Authenticate) 
    .AddAttributes(new RestrictAttribute(RequestAttributes.HttpPost)); 
+0

谢谢。那是票。如果我自己这样说,我特别喜欢第二行。 – vm0112

相关问题