Object reference not set to an instance of an object.

J

Jason Kumpf

I basically built a C# ASP.Net application on my local machine
(running Windows XP, MSSQL2000, IIS) and it has been tested and ready
for deployment. So I deploy it to our server (running Windows 2003
Advanced Server, MSSQL 2000, IIS). So I go to the site locally in
case of an error (http://localhost/myApp/) and it works until a
particular page. All the .aspx.cs page does is call one of my classes
but I get: "Object reference not set to an instance of an object." on
the line where I am calling a method of that class. This doesn't make
sense to me as to why it works on my local machine and not the server
as well as why that error, especially since the defailt.aspx.cs page
calls that class and one of its methods. Here are some snips of code
to clarify.

================================================================
// This is the section where the error occurs, the last statement is
the line.
IPrincipal person = HttpContext.Current.User;
LATools.classes.LDAPUser ldUser = new LATools.classes.LDAPUser();
string username = person.Identity.Name.ToString();
string password = Session["ldapPassword"].ToString();
string context = Session["ldapContext"].ToString();
LdapConnection conn = ldUser.doConnect(
username
, password
, context
);

// This is what IE shows
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:
Line 63: IPrincipal person = HttpContext.Current.User;
Line 64: LATools.classes.LDAPUser ldUser = new
LATools.classes.LDAPUser();
Line 65: LdapConnection conn = ldUser.doConnect(
Line 66: person.Identity.Name.ToString()
Line 67: , Session["ldapPassword"].ToString()


// And just to maybe help more here is the method's code which uses
the
// Novell.Directory.Ldap class.
public LdapConnection doConnect(string username, string password,
string context)
{
string ldapHost = ConfigurationSettings.AppSettings["ldapServer"];
int ldapPort = System.Convert.ToInt32(ConfigurationSettings.AppSettings["ldapPort"]);
LdapConnection conn = new LdapConnection();
conn.Connect(ldapHost, ldapPort);
string ldapDN = findUserDN(conn, username, context);
if (conn.Connected == true)
{
try
{
conn.Bind(ldapDN, password);
}
catch (LdapException exp)
{
string sError = exp.LdapErrorMessage;
return conn;
}
}
return conn;
}

This is critical to our network and since I work for a University our
Quarter is starting soon and we need this to work for our labs.
Thanks!
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Check the configuration of your app, both in the web.config and in IIS and
make sure both are the same.

cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top