I am used to ASP and always use sessions without definitions.
There is a problem with doing something small today. To put it simply:
1. Make a page for setting the session, and then automatically redirect to the page for displaying the session. This is no problem; yes, it was previously done;
2. Today, an old brother first visited the page showing the session. The problem came out,
Note:An error occurred while executing the current Web request. Check the stack trace information for details about the error and the source of the error in the code.
Exception details:System. nullreferenceexception: object reference is not set to the instance of the object.
Source error:
The server error in the "/website1" application.
You have not set the object reference to the instance of the object.
Row 19: //} Row 20: row 21: This. label1.text = session ["name"]. tostring (); row 22:} row 23: protected void checkboxlist1_selectedindexchanged (Object sender, eventargs E)
|
Source file:D:/my documents, Visual Studio 2005/websites/website1/default2.aspx. CSRow:21
Stack trace:
[Nullreferenceexception: object reference is not set to the instance of the object.] Default2.page _ load (Object sender, eventargs E) in D:/My Documents ents/Visual Studio 2005/websites/website1/default2.aspx. CS: 21 system. web. util. callihelper. eventargfunctioncaller (intptr FP, object o, object T, eventargs e) + 31 system. web. util. callieventhandlerdelegateproxy. callback (Object sender, eventargs e) + 68 system. web. UI. control. onload (eventargs e) + 88 system. web. UI. control. loadrecursive () + 74 system. web. UI. page. processrequestmain (Boolean includestagesbeforeasyncpoint, Boolean includestagesafterasyncpoint) + 3034
|
Solution: Add:
If (object. Equals (session ["name"], null ))
{
Session ["name"] = "no value ";
}
OK. Solve the problem.