控制器外的果园主题属性 [英] Orchard Themed Attribute outside controllers

查看:35
本文介绍了控制器外的果园主题属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务,它将覆盖响应正文的内容.
是否可以在覆盖内容的方法中使用主题?

I have a service which will override the content of the response body.
is it possible to use themed within the method which override the content ?

[Themed]
public void forbiddenAlert(IHttpContextAccessor Hca) 
{
  // overriding response body 
}

推荐答案

不,我不认为这会起作用,因为 Themed 属性仅用于装饰控制器.

No, i don't think this will work as the Themed attribute is intended for decorating a controller only.

此外,我认为您没有采用正确的方法来拒绝访问.事件处理程序不应覆盖响应主体(关注点分离,无论如何它很可能不起作用).IAuthorizationServiceEventHandler 应该检查权限并返回是否授予访问权限.授予或未授予权限时发生的情况通常是其他代码部分的问题.我会走这条路:

Also i don't think you follow the right approach for denying access. The event handler should not override the response body (seperation of concerns and it most likely won't work anyway). The IAuthorizationServiceEventHandler should check permissions and return whether access is granted or not. What`s happening when a permission is granted or not granted is normally a concern of other code parts. I would go this route:

  1. 实施适当的权限检查(IAuthorizer, IAuthorizationService) 在所有模块中,在失败时回退到任何合适的,例如重定向到禁止的错误页面
  2. 添加一个 IAuthorizationServiceEventHandler 以相应地实施检查
  1. implement proper permission checks (IAuthorizer, IAuthorizationService) in all modules with a fallback on failure to whatever is suitable e.g. redirecting to a forbidden error page
  2. add an IAuthorizationServiceEventHandler to implement the checks accordingly

这篇关于控制器外的果园主题属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆