A simple solution to session problems in ASP. NET

Source: Internet
Author: User
Tags stack trace

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.