473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Response.Redirect problem in ASP.NET (object refrence not set...)

in my home.aspx page I have a simple login set. when you hit the button it redirects. Here is the code:

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If txtUserID.Text = "" Then
txtUserID.Focus()
Exit Sub
End If
If txtPassword.Text = "" Then
txtPassword.Focus()
Exit Sub
End If
Response.Redirect("UserMain.aspx?userID=" & txtUserID.Text & "&Password=" & txtPassword.Text)
End Sub

Once you hit that button, you get this error message:

Server Error in '/GDCWEB' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
_Default.VarifyUser(String User, String Pass) +171
_Default.Page_Load(Object sender, EventArgs e) +132
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42



on my UserMain.aspx page, my page load code is as follows:

Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack = True Then
UserID = Request.QueryString("userID")
Password = Request.QueryString("Password")
VarifyUser(UserID, Password)
End If
End Sub


varify user:

Private Sub VarifyUser(ByVal User As String, ByVal Pass As String)
Dim strSql2 As String
Dim iDr2 As IDataReader
Dim strErr As String

strSql2 = "Select OPER from OPER Where OPER='" & UserID & "'"
If OdbcGetDataReader(cnOper, strSql2, iDr2, strErr) = False Then
lblHello.Text = strErr
btnReturn.Visible = True
iDr2.Close()
Exit Sub
End If

If iDr2.Read = True Then
Dim vUser As String = Trim(iDr2("OPER"))
If UserID = vUser Then
VarifyPass(User, Pass)
End If
Else
lblHello.Text = "Invalid Entry"
btnReturn.Visible = True
Exit Sub
End If

End Sub


varifypass:

Private Sub VarifyPass(ByVal User As String, ByVal Pass As String)
Dim strSql As String
Dim strErr As String
Dim iDr As IDataReader
strSql = "Select PASS from OPER Where OPER='" & User & "'"
If OdbcGetDataReader(cnOper, strSql, iDr, strErr) = False Then
lblHello.Text = strErr
btnReturn.Visible = True
Exit Sub
End If

While iDr.Read
varPass = Trim(iDr("PASS"))
If Pass = varPass Then
lblHello.Text = "Hello, " & User
LoadPage()
Else
lblHello.Text = "Invalid Entry"
btnReturn.Visible = True
End If
Exit While
End While
iDr.Close()
End Sub

All that LoadPage() does is set some buttons to visible=true.

Any idea guys? Thanks!
Jun 9 '06 #1
3 8074
After playing around with it even more, it seems that its an authentication problem. It runs fine and connects to the database when run via a compile within VS 2005, but when run off our server, it doesnt want to connect, therefore causing the above error. Any ideas?
Jun 9 '06 #2
I'm also using a DSN for the connection string to the database. It works when running from a compile and off the local port, but doesnt work when on our webserver.
Jun 9 '06 #3
I now think it could be because in my code I don't put in a default value for my IDataReaders. I get the warning at the bottom of the screen

Variable 'iDr' is passed by reference before it has been assigned a value. A null reference exception could result at runtime.

And thats exactly what its doing. What default variable can I have it set to so that it wont actually run.
Jun 9 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
4
by: Max Dupenois | last post by:
I've seen numerous articles with similair (similar sp?) titles to this in my search.. unfortunately none of them seem to contain what i want, (or if they do i need someone to point out my stupidity...
7
by: Anne | last post by:
hie there, i want to be able to pass multiple parameters to another page. currently, i am able to do so, but somehow i feel it is not the correct way to do it. below is part of what i have so far....
6
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
1
by: joseph pattom | last post by:
Hi all i am using <customErrors mode="On" defaultRedirect="ErrorDisplay.aspx"/> in my web.config file and getting redirected to "ErrorDisplay.aspx" in almost all the unhandled exceptions but in...
10
by: Niggy | last post by:
I get an error - any help appreciated. System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object...
15
by: KBuser | last post by:
I recently developed an internal website with various queries against our SQL server. I added buttons with Response.Redirect. These buttons do not work with Internet Explorer, however when using...
4
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the...
12
by: gigi | last post by:
How to send more than one value using response redirect? For example i can send one like this response.Redirect "pregled.asp?ime=" & strUserName but how to send two or more values? I tried...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.