小编Sat*_*i K的帖子

自定义 AuthorizeAttribute 被调用太多次

我目前正在开发一些安全措施来保护网络服务调用。我决定扩展授权属性并覆盖 isAuthorized 函数以及 ActionFilterAttribute OnActionExecuted。但是,当我调试程序时,我注意到如果我要在该类中的 api 函数上添加 [Authorize(Roles = "Read")] 类级别和 [Authorize(Roles = "Admin")],则 isAuthorized总共被调用了 3 次。这可能不是什么大问题,但由于在我的 isAuthorized 中,我正在数据库中创建和验证令牌。如果我能够消除这个多余的过程并且每次服务调用只调用一次 isAuthorized ,那将是理想的。

  public class CustomuAuthorizeAttribute : AuthorizeAttribute
{

    protected override bool IsAuthorized(HttpActionContext actionContext)
    {
        bool allowedAccess = true;
        ... logic

    }
   }
Run Code Online (Sandbox Code Playgroud)

覆盖执行的 OnAction。即使 isAuthorized 被命中 3 次,这实际上也只会被命中一次。

    public class CustomAuthorizeFilter : ActionFilterAttribute
{

    public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    {
     .. logic
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑 我发现将 [AttributeUsage(AttributeTargets.Method| AttributeTargets.Class)] 添加到 authorizeattribute calss 解决了被多次调用的问题

c# asp.net authorization asp.net-web-api

5
推荐指数
0
解决办法
1373
查看次数

使用imagePickerController委托函数时获取不明确的引用:

我试图覆盖UIImagePickerControllerDelegate中的imagePickerController函数.但是,我似乎得到一个错误:

Ambiguous reference to member 'subscript'
Run Code Online (Sandbox Code Playgroud)

我做了多次谷歌搜索,这似乎对其他人都很好吗?

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]){


    myImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage

    self.dismiss(animated: true, completion: nil)


}
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激.谢谢

ios swift

3
推荐指数
1
解决办法
785
查看次数

C++指针数组内存分配与普通数组

我正在玩C++,我意识到指针数组和常规数组之间存在显着差异.

char *myString1 = new char[1];
char myString2 [3];

myString1[0] = 'a';
myString1[1] = 'b';
myString1[2] = 'c';
myString1[3] = 'd';

myString2[0]='a';
myString2[1]='b';
myString2[2]='c';
myString2[3]='d';
Run Code Online (Sandbox Code Playgroud)

我很困惑为什么myString1编译甚至用简单的for循环打印每个字符都没有问题,即使我只是初始化初始大小为1.

但是,myString2似乎给了我编译错误,因为我初始化了一个超出数组边界的值.

c++ arrays pointers out-of-memory

0
推荐指数
1
解决办法
101
查看次数