Click here to Skip to main content
16,021,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a login page. After login I can Upload some file or data in my domain. But when I uploading most of the time it fails and shows following errors an also it takes long time to upload. How can I reduce the time and also how can I over come the following problem?

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:

Line 17:     protected void Page_Load(object sender, EventArgs e)
Line 18:     {
Line 19:         Session["user_id"].ToString();
Line 20:     }
Line 21:     protected void Page_Init(object sender, EventArgs e)


Source File: c:\hostingspaces\bhimpurs\bhimpurswamijividyapith.co.in\wwwroot\ADMIN\Admin_MasterPage.master.cs    Line: 19 
Posted
Updated 6-Jun-12 21:42pm
v2
Comments
db7uk 7-Jun-12 4:19am    
I dont get the session .ToString(). If there is no session with a userId in it then the .ToString will throw the null exception.

The upload time will be very dependant on the upload speed of the connection. what size file are you uploading?

If it is taking that long, then your session may have expired, in which case you could get this error. You can try setting the session duration to a higher value: MSDN[^] but as it says, this is a bad idea.

Instead of the session, why not store the user ID in a cookie?
 
Share this answer
 
Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line (Here line19). Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.

It looks like your session is getting timedout and hence when you try to use it, it throws an exception. 2 things:
1. You should always check for null with sessions before using as a good practice
2. if it is taking really such a long time (session timeout default time 20 min) then you need to increase the timeout in your web.config file, like:
Write under system.web section in web.config (for say 60 minutes):
XML
<sessionState timeout="60" mode="InProc" />


Refer: MSDN: sessionState Element (ASP.NET Settings Schema)[^]
 
Share this answer
 
v2

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