首页 新闻 会员 周边 捐助

application中数据保存的问题

0
悬赏园豆:30 [已关闭问题]
<P>最近要实现一个功能,想保存用户最近查询的数据,网址:<A title=http://www.vvcha.cn/huoche.aspx href="http://www.vvcha.cn/huoche.aspx" target=_blank><FONT color=#800080>http://www.vvcha.cn/huoche.aspx</FONT></A> <BR></P> <P>我的实现方法: <BR><BR>1. 定义了一个类A,在A里面定义了一个数组,提供了数据添加的方法add() 。 <BR>2. 在Application_Start里面示例化这个类,并把实例化后的对象保存到application里面。 <BR>&nbsp; A a=new A(); <BR>&nbsp; Application["zhuangtai"] = a; <BR><BR>3.在用户查询后,把a取出来,调用相关的方法 <BR>&nbsp; A a=(A)Application["zhuangtai"]; <BR>&nbsp; a.add();&nbsp; //把用户输入的查询数据添加到类A的数组里面。 <BR>4.在需要显示的页面,取出a中的数据。 <BR>&nbsp; <BR>问题:发现用户查询的数据只能保存很短的时间,不知道什么原因? </P> <P>类A的代码<BR></P> <DIV class=cnblogs_code><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;A<BR><IMG id=Codehighlighter1_19_492_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_19_492_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_19_492_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_19_492_Closed_Text').style.display='inline';" src="http://space.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_19_492_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_19_492_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_19_492_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_19_492_Open_Text').style.display='inline';" src="http://space.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_19_492_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://space.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_19_492_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_74_99_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_74_99_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_74_99_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_74_99_Closed_Text').style.display='inline';" src="http://space.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_74_99_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_74_99_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_74_99_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_74_99_Open_Text').style.display='inline';" src="http://space.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">[]&nbsp;ary&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">[]</SPAN><SPAN id=Codehighlighter1_74_99_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://space.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_74_99_Open_Text><SPAN style="COLOR: #000000">{</SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;count1;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_170_204_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_170_204_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_170_204_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_170_204_Closed_Text').style.display='inline';" src="http://space.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_170_204_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_170_204_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_170_204_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_170_204_Open_Text').style.display='inline';" src="http://space.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;zhuangtai()&nbsp;</SPAN><SPAN id=Codehighlighter1_170_204_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://space.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_170_204_Open_Text><SPAN style="COLOR: #000000">{&nbsp;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count1</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;Datain(&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;tmp)<BR><IMG id=Codehighlighter1_256_379_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_256_379_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_256_379_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_256_379_Closed_Text').style.display='inline';" src="http://space.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_256_379_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_256_379_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_256_379_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_256_379_Open_Text').style.display='inline';" src="http://space.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_256_379_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://space.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_256_379_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ary[count1]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;tmp;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count1&nbsp;</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">1</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(count1&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">7</SPAN><SPAN style="COLOR: #000000">)<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;Dataout(&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;shuju)<BR><IMG id=Codehighlighter1_431_484_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_431_484_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_431_484_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_431_484_Closed_Text').style.display='inline';" src="http://space.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_431_484_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_431_484_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_431_484_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_431_484_Open_Text').style.display='inline';" src="http://space.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_431_484_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://space.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_431_484_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;ary[shuju].ToString();<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN></DIV>
好好学习,天天向上的主页 好好学习,天天向上 | 初学一级 | 园豆:68
提问于:2008-07-28 16:51
< >
分享
其他回答(3)
0
Application 这么用才安全 Application.Lock(); 。。。。。。。。。。。。 Application.UnLock() ; 常理来说application不会丢失,除非应用程序重新启动了
無尽海 | 园豆:540 (小虾三级) | 2008-07-28 17:20
0
可以存储的东西很多啊,cookies session application 比较优缺会发现....
Jared.Nie | 园豆:1940 (小虾三级) | 2008-07-28 21:23
0
建议用Cache来存储
Sharper代码人生 | 园豆:225 (菜鸟二级) | 2008-07-29 00:38
0
用application来保存数据,有时候是不安全的,很容易重新初始化。如果你在IIS的应用程序池里设置了多个圆的话,或者session的保存位置不在inproc时,都有可能丢失数据。
李.net | 园豆:730 (小虾三级) | 2008-07-29 13:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册