Orchard Themed Attribute outside controllers

大憨熊 提交于 2019-12-02 11:02:44

问题


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 
}

回答1:


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

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. 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


来源:https://stackoverflow.com/questions/48400301/orchard-themed-attribute-outside-controllers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!