2017-06-14 58 views
1

以下在本地机器(vs 2015)中正常工作,但是当我在iis7中发布用户主体时,它将变为null。谁可以帮我这个事。UserPrincipal.current在iis7中返回null,

[ActionName("Login")] 
    [HttpGet] 
    [CacheFilter(TimeDuration = 100)] 
    public async Task<List<Hashtable>> Login([FromUri]string id, string netPwd) 
    { 
     await Task.Delay(100); 
     bool response = false; 

     // Build user id and password strings from KGP network credentials 
     string uid = id; 
     string password = netPwd; 
     Hashtable hashChild = new Hashtable(); 

     List<Hashtable> list = new List<Hashtable>(); 

     // Define LDAP connection 
     DirectoryEntry root = new DirectoryEntry("LdapAccount", uid, password, AuthenticationTypes.Secure); 
     try 
     { 
      object connected = root.NativeObject; 
      UserPrincipal userPrincipal = UserPrincipal.Current; 

      if (HttpContext.Current.User.Identity.IsAuthenticated) 
      { 
       string s = "tri"; 
      } 
      string EmployeeId = userPrincipal.EmployeeId; 

      domainName = System.Environment.UserDomainName; 

}

回答

0

使用系统帐户运行IIS?

+0

我的应用程序在不同的服务器和iis在我的本地系统所以,我发布了应用程序在我的本地系统并添加到iis。我已启用Windows身份验证。 – sukumar2267

+0

它在“ApplicationPoolIdentity”帐户下运行 – sukumar2267

0

最终我得到了这个答案.. 需要添加

using (HostingEnvironment.Impersonate()) 
     { 

//代码在这里

}

- 认证匿名认证,认证通常根据您的应用程序。