Nancy RequiresClaims 失败返回 403。我该如何使用它?
如果模块需要声明,而用户没有声明,则会返回 403 响应。 例如:
this.RequiresClaims(new[] { "SuperSecure" });
或者
this.RequiresValidatedClaims(c => c.Contains("SuperSecure"));
但这只是向用户返回一个空白页面。
对于没有所需声明的用户,我该如何处理? 我可以“捕获”403 并重定向吗?
RequiresClaims 方法返回 void 或使用预请求挂钩抛出 HttpStatusCode.Forbidden。我应该怎么做才能让用户知道发生了什么?
非常感谢, 尼尔
If a module requires a claim, and the user does not have the claim a 403 response is returned.
eg:
this.RequiresClaims(new[] { "SuperSecure" });
or
this.RequiresValidatedClaims(c => c.Contains("SuperSecure"));
but that just returns a blank page to the user.
How do I deal with a user not having the required claim?
Can I 'catch' the 403 and redirect?
The RequiresClaims method returns void or uses the pre-request hook to throw back a HttpStatusCode.Forbidden. What should I do so the user knows what has happened?
Many Thanks,
Neil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过编写自己的帖子请求挂钩(在应用程序级别或模块级别)或通过实现自己的 IErrorHandler,可能包装 默认。
错误处理程序的内容将会发生变化,因此您将能够注册多个错误处理程序(针对不同的错误代码),它的设置就是为了做到这一点(使用“can/do”界面),但由于某种原因我的大脑没有添加它作为一个集合:-)
You can catch it either by writing your own post request hook (either at the app level, or the module level) or by implementing your own IErrorHandler, probably wrapping the default one.
The error handler stuff is going to change so you will be able to register multiple ones (for different error codes), it's setup to do that (with the "can/do" interface) but for some reason my brain didn't add it as a collection :-)