Solved

ASP.NEt site works in Debug but not in production

Posted on 2010-09-17
14
431 Views
Last Modified: 2013-11-26
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?
0
Comment
Question by:silent_waters
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +1
14 Comments
 
LVL 9

Expert Comment

by:xav056
ID: 33701577
try to see if there is anything in the stack trace
0
 

Author Comment

by:silent_waters
ID: 33701781
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
 

Author Comment

by:silent_waters
ID: 33701803
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 9

Assisted Solution

by:xav056
xav056 earned 200 total points
ID: 33701990
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
 
LVL 41

Expert Comment

by:guru_sami
ID: 33702132
Also can your post the code that is causing error i.e. Login_Click
0
 

Author Comment

by:silent_waters
ID: 33702322
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
 
LVL 41

Expert Comment

by:guru_sami
ID: 33702450
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
 

Author Comment

by:silent_waters
ID: 33702646
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
 
LVL 16

Expert Comment

by:13598
ID: 33702781
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
 

Author Comment

by:silent_waters
ID: 33702856
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
 

Author Comment

by:silent_waters
ID: 33702873
Is there a way to get IIS to run the application in a different context?
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 300 total points
ID: 33702902
0
 
LVL 16

Expert Comment

by:13598
ID: 33702912
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
 
LVL 16

Expert Comment

by:13598
ID: 33702929

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question