Wrox Programmer Forums
|
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 26th, 2004, 02:37 PM
Registered User
 
Join Date: Apr 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object reference not set to an instance...

:D Hi everybody! :D

Ive got a problem (for u hackers out there) with the ThePhile website (the download from
 wrox). Every module works fine the only one giving me a hard time is the forums module,
I can view the forums and the topics and their answers. But if I try to add a topic,
response or try to register as a forum user the system goes down on me, and the
following error message is displayed. Could enyone help me? Ive seen a few people with
this problem but nobody seems to know the answer.


Code:
An unexpected error has occurred on this page. The system administrators have been 
notified. Please feel free to contact us with the information surrounding this error.

The error occurred in: http://localhost/ThePhile/Modules/Fo...tMessage.aspx?
Action=NewTopic&ForumID=25

Error Message: Object reference not set to an instance of an object.


Stack Trace: 
System.NullReferenceException: Object reference not set to an instance of an object. at
Wrox.WebModules.Forums.Web.PostMessage.Page_Load(Object sender, EventArgs e) in 
c:\inetpub\wwwroot\thephile\modules\forums\postmessage.aspx.cs:line 93 at 
System.EventHandler.Invoke(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad
(EventArgs e) at System.Web.UI.Control.LoadRecursive() at 
System.Web.UI.Page.ProcessRequestMain()
And this is what line 93 says....


Code:
ViewState["ReferrerUrl"] = Request.UrlReferrer.ToString();
 
Old April 26th, 2004, 03:06 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Are you by any chance running a firewall like Norton Internet Security? There is a Privacy Protection mechanism that blocks sending the URL Referrer. This is also an issue on this forum if you edit one of your own messages. If the firewall blocks the referrer, it makes sense the code crashes.
Another cause is that the page is requested directly. In that case, there is no referrer, as a referrer is only available when you open a page by clicking a link for example on another page.

I think in both case, you can use some defensive coding mechanism to protect your from this error:
Code:
if (Request.UrlReferrer != null)
{
  // Referrer found. Save to ViewState
  ViewState["ReferrerUrl"] = Request.UrlReferrer.ToString();
}
else
{
  // Referrer not found. Reset ViewState, or save / change 
  // anything you see fit.
  ViewState["ReferrerUrl"] = "";
}
Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 26th, 2004, 05:55 PM
Registered User
 
Join Date: Apr 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah tnx man, U did it, U solved the problem. I cant thank u enough :)

domo arigato!!!

 
Old April 27th, 2004, 01:41 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Out of curiosity (and future reference), how did you finally solve the problem?

Was it a firewall that caused the referrer to be empty?

Imar


 
Old April 27th, 2004, 02:22 AM
Registered User
 
Join Date: Apr 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well kind of, It was the Privacy Control in Norton Internet Security, not the firewall itself. This should fix it for you guys out there with the same problem.

Code:
http://www.theboyz.nu/images/norton.jpg
 
Old May 6th, 2004, 09:37 PM
Authorized User
 
Join Date: Jul 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks Imar and steelman for the great posts. I was having the same problem too. I was perplexed because at one point I had the forums working fine. Now I know it was when I had Norton Internet Security 2002 installed. So, my guess is that this problem first started occuring after I installed Internet Security 2003. Turning off Privacy Control fixed the problem for me...

Thanks,
d.

 
Old May 7th, 2004, 02:03 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Just remember that turning off Privacy Control fixes the problem for you as a user, but not for the application. So, anyone else with this kind of Privacy control software will run into the same issue when they visit your forum.

It's best to modify your code so it catches those situations by checking if Request.UrlReferrer is null or not, as I demonstrated in my earlier post.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Suck it Up by Hed Planet Earth (Track 1 from the album: Blackout ) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object reference not set to an instance of an obje rturner003 ASP.NET 2.0 Professional 0 December 26th, 2006 08:30 PM
Object reference not set to an instance of an obj nrathod_97 BOOK: Beginning VB.NET Databases 4 June 21st, 2005 06:35 PM
Object Reference is Not Set to an Instance of an O blackinwhite General .NET 4 February 1st, 2005 05:42 AM
Object reference not set to an instance of an obje williadn General .NET 0 January 18th, 2005 05:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.