【问题标题】:Action Method Should Hit For Particular Links Only动作方法应该只针对特定链接
【发布时间】:2020-01-17 22:37:52
【问题描述】:

如何使操作方法只针对特定链接,

它不应该以其他方式调用。

【问题讨论】:

    标签: c# .net asp.net-mvc-4 asp.net-mvc-5


    【解决方案1】:

    创建自定义授权以检查请求是否通过授权操作链接或按钮发送。

    这样做,

    
    
     [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
        public class AuthorizationForAction : AuthorizeAttribute
        {
    
            public override void OnAuthorization(AuthorizationContext filterContext)
            {
                  //your custom logic to authorize your action
            }
    }
    

    并在控制器上的特定操作上使用 AuthorizationForAction 标签

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 2012-12-29
      • 2020-02-04
      相关资源
      最近更新 更多