嗨,我的 asp.net 应用程序有问题。
问题是我可以在我的本地主机上毫无问题地执行我的应用程序,但是如果我在服务器上的IIS7中安装它,则会出现错误。我尝试查找错误,并在一个区域中选择了错误。
以下是错误消息:
Object reference not set to an instance of an object.
bei linde_wiemann_gastzugang.linde_wiemann_daten.IsGroupMember(String dc, String user, String group) in D:ProgrammierungVisual_Studio_2010Projektelw_gastzuganglw_gastzuganglw_daten.cs:Zeile 30.
这是代码:
public static bool IsGroupMember(string dc, string user, string group)
{
try
{
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, dc))
{
bool found = false;
GroupPrincipal p = GroupPrincipal.FindByIdentity(ctx, group);
UserPrincipal u = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, user);
found = p.GetMembers(true).Contains(u); //I think the error is here :(
p.Dispose();
u.Dispose();
return found; // <-- Zeile 30
}
}
catch (Exception ex)
{
EventLogManager.CreateEventLog("Gastzugang",ex.Message + " : " + dc + " - " + user + " - " + group);
return false;
}
我尝试使用硬编码值如何真实,并且它适用于它们:/是什么让我不能使用此代码的 IIS?
尝试将 p 和 u 放入一个 using 子句中:
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, dc))
{
using (GroupPrincipal p = GroupPrincipal.FindByIdentity(ctx, group))
{
using (UserPrincipal u = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, user))
{
return p.GetMembers(true).Contains(u);
}
}
}
我认为您遇到了处置问题。