Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 获取HttpContext.Current.User.Identity.Name时发生资源泄漏_Asp.net_C# 4.0_Asp.net Web Api_Memory Leaks_Coverity - Fatal编程技术网

Asp.net 获取HttpContext.Current.User.Identity.Name时发生资源泄漏

Asp.net 获取HttpContext.Current.User.Identity.Name时发生资源泄漏,asp.net,c#-4.0,asp.net-web-api,memory-leaks,coverity,Asp.net,C# 4.0,Asp.net Web Api,Memory Leaks,Coverity,我使用HttpContext来检索即将到来的HTTP请求的当前用户名,但在运行coverity analysis时,它报告了一个资源泄漏 public class UsersController:ApiController { private string userName; public UsersController() { if (HttpContext.Current != null) {

我使用HttpContext来检索即将到来的HTTP请求的当前用户名,但在运行coverity analysis时,它报告了一个资源泄漏

    public class UsersController:ApiController
    {
      private string userName;
      public UsersController()
      {
        if (HttpContext.Current != null)
        {
            userName = HttpContext.Current.User.Identity.Name;
        }
    }
    //I defined customized identity
    public class MyIdentity : IIdentity
    {
        private string name;
        public string AuthenticationType
        {
            get { return "Custom"; }
        }

        public bool IsAuthenticated
        {
            get { return true; }

        }

        public string Name { get; set; }

 }
在Coverity报告中,它说 2.alloc_fn:从分配方法Identity.get返回一个新资源。(虚拟调用解析为System.Security.Claims.ClaimsPrincipal.Identity.get。) 3.noescape:Resource System.Web.HttpContext.Current.User.Identity未关闭或保存在Name.get中。(虚拟调用解析为Org.Abc.HttpModules.MyIdentity.Name.get。)

CID 51307:资源泄漏(资源泄漏)
4.泄漏的\u资源:未能保存或关闭由System.Web.HttpContext.Current.User.Identity创建的资源会泄漏该资源。

IIdentity由实现。WindowsIdentity还实现IDisposable,因此需要在创建它之后进行处理。您可以通过调用Dispose方法来实现这一点


但是,由于您使用的是自己的IIdentity实现,我认为这里的问题是Coverity不确定该身份是否是一次性的,因此在谨慎方面存在错误。

您找到解决问题的方法了吗?@Abdulahademonty我直接与Coverity支持部门联系,他们认为这是假阳性,因此,我的实现没有问题:)