Click here to Skip to main content
15,889,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi friends,

a project which i am working now, it needs to get data from another webpage.

everything is fine in my system locally... but when i upload it to godaddy... it's giving error pls check the image below

http://postimg.org/image/6v0u503uv/[^]

pls let me know the solution

thank you
Posted

You have two issues...one you are not coding defensively so are prone to these errors. There is no guarantee that your session variables exist so you have to check first. Secondly it looks like you might be storing ints as strings, which you shouldn't. To store an int use

C#
Session["session"] = myIntVar;


to read it back;

C#
int x = 0;
if (Session["session"] != null)
{
    x = (int)Session["session"];
}


That'll stop the error, but now you code needs to know what to do when there is no session variable, it has to do something sensible like show a message, redirect to a login page, whatever.

Your next issue is why the session is empty. It could be that godaddy are reducing your session timeouts quite low, it could be that sessions aren't working at all. We don't know.

Lastly, good luck with your weight issues but please stay away from snake-oil products from the internet :)
 
Share this answer
 
Session["session"] may be null, you need to find the reason for that. to avoid the exception you can first check object for null and then convert to integer as below
C#
if(Session["session"]!=null)
{
  int a =(int)Session["session"];
}
 
Share this answer
 
There's only one possible cause for a null reference in that line of code. Your Session["session"] call returned null. Your code never checks to see if that call returned anything. It just assumes that there was a value in the Session under the key called "session".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900