Solved

ASP.NEt site works in Debug but not in production

Posted on 2010-09-17
14
427 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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