URGENT Getting null reference errors on 404??

D

David Lozzi

Hello there,

I'm getting the following error

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

at shopping_bag.GetBagTotals()



which then causes this following error which stops the application pool my
web application is running on

EventType clr20r3, P1 w3wp.exe, P2 6.0.3790.1830, P3 42435be1, P4 app_code,
P5 1.0.2587.41853, P6 45c1694a, P7 a6, P8 0, P9
system.nullreferenceexception, P10 NIL.


The GetBagTotals does not have a null reference in it from what I can see. I
only get this error when a visitor hits a page that is non existent, for
example www.domain.com/otherpage.aspx. (recently updated the site so a lot
of pages are no longer there). When these pages are hit I get the following:

Explanation: The Web server connection was closed.
Technical Information (for support personnel)

a.. Error Code 64: Host not available
b.. Background: The connection to the Web server was lost.


And the two errors listed above. I have the 404, 404;2,404;3 in IIS set to
go to an aspx page which works great if someone goes to an .html page that
is no longer available. Weird eh?

So if a user tries to visit a page that is no longer available and it ends
in aspx, they don't get a 404 error, they get what is displayed above and
then a null reference error occurs. If a user tries to visit a page that
ends in .html they get the correct 404 error page and no null errors.

Any ideas why aspx pages are not responding to a 404?

Thanks,

David Lozzi
 
D

David Lozzi

I tried adding

<customErrors mode="RemoteOnly">

<error statusCode="400" redirect="notfound.aspx" />

<error statusCode="401" redirect="notfound.aspx" />

<error statusCode="403" redirect="notfound.aspx" />

<error statusCode="404" redirect="notfound.aspx" />

<error statusCode="408" redirect="notfound.aspx" />

<error statusCode="500" redirect="notfound.aspx" />

<error statusCode="503" redirect="notfound.aspx" />

</customErrors>



To the web.config file and that didn't work either. Still get the previously
stated errors.

I'm sorry, the server is a Win2003 Standard SP1.



Thanks!
 
D

David Lozzi

oops, asp.net 2.0 application


David Lozzi said:
I tried adding

<customErrors mode="RemoteOnly">

<error statusCode="400" redirect="notfound.aspx" />

<error statusCode="401" redirect="notfound.aspx" />

<error statusCode="403" redirect="notfound.aspx" />

<error statusCode="404" redirect="notfound.aspx" />

<error statusCode="408" redirect="notfound.aspx" />

<error statusCode="500" redirect="notfound.aspx" />

<error statusCode="503" redirect="notfound.aspx" />

</customErrors>



To the web.config file and that didn't work either. Still get the
previously stated errors.

I'm sorry, the server is a Win2003 Standard SP1.



Thanks!
 
T

Tim Mackey

hi David,
it is clear that some of your application code is running when the
non-existent page is requested.
this is probably in application_beginrequest or session_start in
global.asax?
if not there must be some other httphandler or module running that is
invoking your code.
can you debug the server and set a breakpoint before the nullref exception?
then look at the stacktrace and see where it comes from. it will probably
say <non user code> but you may get a clue.

hope this helps
tim
 
T

Tim Mackey

also david, just to add to my previous reply.
i would bet a tenner that your shopping_bag object is null, and this is the
reason for the exception, rather than the exception occuring inside the
method itself.

tim
 
J

Juan T. Llibre

Try this :

Errors.aspx:
-----------------
<html>
<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim errMessage As String = ""
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException, HttpException)
Select Case checkException.GetHttpCode
Case 400
errMessage &= "Bad request. The file size is too large."
Case 401
errMessage &= "You are not authorized to view this page."
Case 403
errMessage &= "You are not allowed to view that page."
Case 404
errMessage &= "The page you have requested can't be found."
Case 408
errMessage &= "The request has timed out."
Case 500
errMessage &= "The server can't fulfill your request."
Case Else
errMessage &= "The server has experienced an error."
End Select
Else
errMessage &= "The following error occurred<BR>" & appException.ToString
End If
ErrorMessage.Text = errMessage & "<BR>We're sorry for the inconvenience."
Server.ClearError()
End Sub
</script>

<body>
<hr>
<asp:label id="ErrorMessage" font-size="12" font-bold="true" runat=server/>
<hr>
<p>Return to <a href="http://www.server.com/"> The site's entry page</a>
</body>
</html>
---------------

Modify the cases to taste.

Some will not be available because they're not customizable,
but 404s will be caught and the user will be redirected to the "errors.aspx" page.

You could also modify the response to perform other tasks.

Then, in your web.config, add either:

<customErrors mode="RemoteOnly" defaultRedirect="Errors.aspx"/>

or

<customErrors mode="On" defaultRedirect="Errors.aspx"/>
 
D

David Lozzi

Oops some more, sorry for the late info... ISA 2004 Standard is also running
on this server. The more I research this error I see more and more ISA
related issues however nothing pertaining to this yet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top