化工分析师证书有哪些:关于Session的错误

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/30 18:34:12
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 31: username = Session["username"].ToString();

运行时出错,怎么回事?
难道使用session的时候也要象使用变量一样先声明一下吗?

应该这样写:username=(string)Session["username"]