Solved

ASP.NEt site works in Debug but not in production

Posted on 2010-09-17
14
428 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
  • 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now