以下在本地机器上工作正常(vs 2015)但是当我在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 :(得分:0)
IIS是否使用SYSTEM帐户运行?
答案 1 :(得分:0)
最后我得到了答案.. 需要添加
using (HostingEnvironment.Impersonate())
{
//代码在这里
}
- 身份验证是匿名身份验证,通常基于您的应用程序进行身份验证。