Furion icon indicating copy to clipboard operation
Furion copied to clipboard

Furion documentation - dynamic-api-controller

Open monksoul opened this issue 4 years ago • 3 comments

monksoul avatar Dec 16 '21 09:12 monksoul

如下代码,注入接口失败,提示:Unable to resolve service for type IMyService 这种情况下,该如何实现自动注入啊。 [DynamicApiController] [ApiDescriptionSettings(Tag = "测试服务", Name = "mytest")] public class TestService { private readonly IMyService _service;

    public TestService(IMyService service) {
        _service = service;
    }

    [HttpPost]
    [ApiDescriptionSettings(Name = "objinf")]
    public ObjClass GetObjInfo(QueryDto qm) {
        return _service.GetObjInfo(qm.id);
    }
 }

microsofter avatar Mar 09 '22 11:03 microsofter

上面的问题搞好了,分层的问题,动态加载配置里少了一个dll

microsofter avatar Mar 09 '22 11:03 microsofter

有个场景,期望对部分接口添加Action filter,以实现ip安全认证,

public class ClientIpCheckActionFilter : ActionFilterAttribute
{
    private readonly ILogger _logger;
    private readonly string _safelist;

    public ClientIpCheckActionFilter(string safelist, ILogger logger)
    {
        _safelist = safelist;
        _logger = logger;
    }

    public override void OnActionExecuting(ActionExecutingContext context)
    {
        var remoteIp = context.HttpContext.Connection.RemoteIpAddress;
        _logger.LogDebug("Remote IpAddress: {RemoteIp}", remoteIp);
        var ip = _safelist.Split(';');
        var badIp = true;
        
        if (remoteIp.IsIPv4MappedToIPv6)
        {
            remoteIp = remoteIp.MapToIPv4();
        }
        
        foreach (var address in ip)
        {
            var testIp = IPAddress.Parse(address);
            
            if (testIp.Equals(remoteIp))
            {
                badIp = false;
                break;
            }
        }

        if (badIp)
        {
            _logger.LogWarning("Forbidden Request from IP: {RemoteIp}", remoteIp);
            context.Result = new StatusCodeResult(StatusCodes.Status403Forbidden);
            return;
        }

        base.OnActionExecuting(context);
    }
}

当context.Result置为403,并跳出过滤器,之后执行SucceededUnifyResultFilter过滤器OnActionExecutionAsync函数,并返回statuecode=200,这不是期望的结果。 原生net6框架下会返回的403状态,furion框架下有什么方案可以实现返回403状态?

Golone avatar Apr 25 '22 10:04 Golone