ASP.NEt site works in Debug but not in production

I am building an intranet site for my company. I have a server with visual studio 2010 and IIS 7.5 installed that I am using to build the site. Easier to use a single machine until the site goes live.
The site uses forms authentication. When i run the site from VS 2010 it works perfectly, but when I publish it I get an Object reference not set to an instance of an object error. Is this something obvious, and if not, how do I go about trying to debug this?
silent_watersAsked:
Who is Participating?
 
xav056Commented:
try to see if there is anything in the stack trace
0
 
silent_watersAuthor Commented:
Nothing useful. See atached.
[Exception: Error authenticating. Object reference not set to an instance of an object.]
   CityIntranet.Logon.Login_Click(Object sender, EventArgs e) in C:\Users\administrator.CITY\documents\visual studio 2010\Projects\CityIntranet\CityIntranet\Logon.aspx.vb:32
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691

Open in new window

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
silent_watersAuthor Commented:
Is there a way to get VS to use IIS when debugging rather than its own internal server? this might give me more information.
0
 
xav056Connect With a Mentor Commented:
error is hapening in logon.aspx probablt line 32
It is probably related to a securty authentucation issue.
To use IIS in VS right lick on the project select properties-->then go to the web tab on the left and in the servers sections select USE IIS, specify the url there and make sure you create the virtual directory
0
 
guru_samiCommented:
Also can your post the code that is causing error i.e. Login_Click
0
 
silent_watersAuthor Commented:
There are only 29 lines in logon.aspx. Codebehind is atached, but I don't see how this can be at fault if it works perfectly in debug mode.
Imports CityIntranet.FormsAuth

Partial Public Class Logon
    Inherits System.Web.UI.Page

    Sub Login_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogin.Click
        Dim adPath As String = ConfigurationManager.AppSettings("LdapUsersString")
        Dim adAuth As LdapAuthentication = New LdapAuthentication(adPath)
        Try
            If (True = adAuth.IsAuthenticated(txtUsername.Text, txtPassword.Text)) Then
                Dim userGuid As String = adAuth.Synchronise()

                Session("GUID") = userGuid

                Dim authTicket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, _
                     txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(60), False, userGuid)

                Dim encryptedTicket As String = FormsAuthentication.Encrypt(authTicket)

                Dim authCookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)

                Response.Cookies.Add(authCookie)

                Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, False))

            Else
                errorLabel.Text = "Authentication did not succeed. Check user name and password."
            End If

        Catch ex As Exception
            errorLabel.Text = "Error authenticating. " & ex.Message
            'Throw New Exception("Error authenticating. " & ex.Message)
        End Try
    End Sub
End Class

Open in new window

0
 
guru_samiCommented:
my doubt is "adAuth" is null due to some reason. Can you put a for null on that before using that like:

If adAuth IsNot Nothing Then
 'your try catch block code

Else
   errorLabel.Text= " adAuth is null"

End If
0
 
silent_watersAuthor Commented:
I've switched to using IIS to debug the code which has allowed me to use breakpoints and narrow down the problem. The issue is in a section of code that is supposed to get a list of groups that the user is a member of.
It gets as far as the line "result = search.FindOne()", but strangely I never get the exception text as part of the error message.
I'm guessing it must be a permissions thing or something. The application is clearly not able to access the directory, but I don't know why not if it works in the internal server of VS. The connection string must be correct or it wouldn't work at all.

Dim search As DirectorySearcher = New DirectorySearcher(ConfigurationManager.AppSettings("LdapUsersString"))
            search.Filter = "(cn=" & cn & ")"
            search.PropertiesToLoad.Add("memberOf")
                        
            Dim result As SearchResult
            Try
                result = search.FindOne() <--ERROR OCCURS HERE
            Catch ex As Exception
                Throw New Exception("Error obtaining user details with directory searcher. " & ex.Message & ", " & ex.InnerException.ToString)
            End Try

Open in new window

0
 
13598Commented:
Maybe it is that cn only contains the username which is fine to run locally and to work on your server it may need domain\username format?
What is the value in cn?
0
 
silent_watersAuthor Commented:
The value is the full user name, which is proved to be correct by this point because the user has already been authenticated. It doesn't work if I put domain\ in front because it is looking at the cn attribute in the directory, which doesn't contain that data in the string. It is not trying to authenticate at this point, just to search the specified OU for an object with that string in the cn attribute.  
0
 
silent_watersAuthor Commented:
Is there a way to get IIS to run the application in a different context?
0
 
13598Commented:
So cn is the username which you used to authenticate?
Then look at your LdapUsersString string. If the server is not finding it but your PC is then something in your LdapUsersString could be the cause. Maybe the settings file does not exist in the server. Can you see it in your server? Did you include it (copy local true)?
0
 
13598Commented:

So cn is the username which you used to authenticate?
Then look at your LdapUsersString string. If the server is not finding it but your PC is then something in your LdapUsersString could be the cause. Maybe the settings file does not exist in the server. Can you see it in your server? Did you include it (copy local true)? If it exists can you compare the values to the one in your PC?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.