本文介绍了"/"应用程序中的服务器错误.使用(C#).NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
—SA
Most likely Session["lodgingID"] is null. You cannot assume the session state "lodgingID" always exist. How do you know?
See msdn.microsoft/en-us/library/03sekbw5(v=VS.85).aspx[^].
The mere fact you use immediate constant "lodgingID" in code (hard-coded) is suspect. There are no situations when you should use immediate constant like that. How can you support it? If you write the same constant in more than one place, how can you guarantee it''s the same? Compiler won''t warn you.
—SA
我的应用程序可以在localhost上正常运行,但是会尽快出现此错误 当我把它放在服务器上时.我知道当对象具有时会发生此错误 尚未在引用之前实例化,但为什么不应该发生 在本地主机中? 整个错误消息如下所示:
Hi, My application works fine on the localhost but spits this error as soon as I put it on the server. I know this error occurs when an object has not been instantiated prior to a reference, but why shouldn''t it happen in the localhost? Here''s what the the whole error msg looks like:
Server Error in ''/'' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object.我的代码:
my code:
iBookings.Lodgings.Lodging objLodging = new iBookings.Lodgings.Lodging(); objLodging.ID = (int)Session["lodgingID"]; string name = objLodging.GetName();Thanx
Thanx
推荐答案最可能的Session["lodgingID"]是null.您不能假定会话状态"lodgingID"始终存在.你怎么知道? 请参阅 msdn.microsoft/en-us/library/03sekbw5(v = VS.85).aspx [ ^ ]. 仅在代码(硬编码)中使用立即常数"lodgingID"的事实值得怀疑.在任何情况下,都不应使用此类的立即数.您如何支持它?如果您在多个地方写相同的常量,那么如何保证它是相同的呢?编译器不会警告您.
可能是Session["lodgingID"]对象为空或根本没有实例化.在转换为所需类型之前,请检查会话对象.以下代码帮助您执行此操作. This probably happens the Session["lodgingID"] object is empty or not instantiated at all.Check the session object before casting to the required type.The following code help you how to do this. //... if(Session["lodgingID"]!=null) objLodging.ID = (int)Session["lodgingID"]; // ...
希望对您有所帮助.
I hope this helps you well.
感谢大家的快速解答... 终于我解决了这个问题. 这是与错误有关的问题 类中的代码中的数据库的连接字符串(objLodging.GetName();) 还是要感谢! Thank you all of you for your quick answers... Finally I solved this problem.. It was a problem that has to do with something wrong with the connection string to the Database in the code inside my class ( objLodging.GetName();) Thnks anyway!
更多推荐
"/"应用程序中的服务器错误.使用(C#).NET
发布评论