小编azh*_*ahi的帖子

ASP.NET Core Web API自定义AuthorizeAttribute问题

我正在研究 ASP.NET Core Web API。我正在尝试创建自定义Authorize属性,但我陷入困境。我不明白我错过了什么。我有以下属性和过滤器代码Authorize

public class AuthorizeAttribute : TypeFilterAttribute
{
    public AuthorizeAttribute(params string[] claim) : base(typeof(AuthorizeFilter))
    {
        Arguments = new object[] { claim };
    }
}

public class AuthorizeFilter : IAuthorizationFilter
{
    readonly string[] _claim;

    public AuthorizeFilter(params string[] claim)
    {
        _claim = claim;
    }

    public void OnAuthorization(AuthorizationFilterContext context)
    {
        var IsAuthenticated = context.HttpContext.User.Identity.IsAuthenticated;
        var claimsIndentity = context.HttpContext.User.Identity as ClaimsIdentity;

        if (IsAuthenticated)
        {
            bool flagClaim = false;
            foreach (var item in _claim)
            {
                if (context.HttpContext.User.HasClaim("Role", item)) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-webapi

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

霍夫曼编码 C++ 代码抛出致命错误

我正在为著名的霍夫曼编码算法编写代码。我收到一个致命错误,将系统变成蓝屏然后重新启动。此错误发生在具有递归调用的 display_Codes 中。错误发生在以下几行:

display_Codes(root->l, s + "0"); 
display_Codes(root->r, s + "1" );
Run Code Online (Sandbox Code Playgroud)

以下是完整代码。

#include <iostream>

#include <bits/stdc++.h> 

using namespace std;




class HeapNode_Min {




public:


char d; 

unsigned f; 

HeapNode_Min *l, *r;
HeapNode_Min(char d, unsigned f) 
{ 

      this->d = d;
      this->f = f;
}




~HeapNode_Min()
 {
   delete l;
   delete r;
 } 
}; 



class Analyze {  

  public:
    bool operator()(HeapNode_Min* l, HeapNode_Min* r) 
    { 
        return (l->f > r->f);
    } 
}; 



void display_Codes(HeapNode_Min* root, string s) 
{   
    if(!root) 
        return; 

    if (root->d != '$') 
        cout …
Run Code Online (Sandbox Code Playgroud)

c++ huffman-code

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