使用Session将动态值从一个ASP页面传递到另一个ASP页面? [英] Passing dynamic value from one ASP page to another using Session?

查看:216
本文介绍了使用Session将动态值从一个ASP页面传递到另一个ASP页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们我试图将变量从一个页面传递到另一个页面。在搜索时,我发现使用了QueryString方法或者Session用于传递变量。我不喜欢QueryString方法,因为它在URL中显示数据,可以修改,所以我去了会话。



现在我在asp中添加了一个DataGridView,它有一个每行按钮。单击此按钮后,将创建一个会话变量,其中包含单击按钮的行的第1列的值,然后重定向到我正在使用此会话变量的另一个页面。



现在的问题是,当我使用Visual Studio调试器时,这工作正常,变量值根据按钮单击不断变化。但是,一旦我将网站上传到托管,变量就会在我第一次单击DataGridView中的按钮时创建,但是当我再次按下不同行中的按钮时,变量值不会更改。它保持不变,除非我在重定向页面的浏览器中按F5,然后才会更新值。



我认为该值存储在浏览器的缓存中并且不会t改变,直到我强制刷新页面。我该怎么做才能解决这个问题?除了上面提到的两种方法之外还有其他传递变量的方法吗?



用于创建会话和重定向的代码:



Guys I am trying to pass a variable from one page to another. Upon searching I found that either QueryString method is used or Session is used for passing variable. I don't like QueryString method as it displays data in URL which could be modified so I went for sessions.

Now I have added a DataGridView in asp which has a button in each row. Upon clicking this button, a session variable is created having the value of 1st column of the row in which the button was clicked and then it redirects to another page in which I am using this session variable.

Now the problem is, when I was using the Visual Studio debugger, this was working fine and the variable value kept changing according to the button click. But once I uploaded the site to hosting, the variable is created the first time I click the button in DataGridView but when I press the button again in different row, the variable value doesn't change. It remains constant, unless I press F5 in browser on the redirected page, only then the value gets updated.

I think the value gets stored in browser's cache and doesn't change until I force refresh the page. What should I do to solve this problem? is there any other way to pass variable other than the above two mentioned methods?

Code for creating session and redirecting :

GridDataItem item = (GridDataItem)e.Item;
string ticketid = item["ID"].Text;
Session["viewID"] = ticketid;
Response.Redirect("View.aspx");





检索会话代码:





Code for retrieving session :

String s = Session["viewID"] as String;





我也想避免使用cookies,许多用户在浏览器中禁用了cookie,因此使用cookies不会是最佳的。



I would also like to avoid using cookies, many users have cookies disabled in their browsers so using cookies wont be optimal.

推荐答案

尝试



Try

Response.Redirect("View.aspx", false);





我认为回复.redirect结束响应。 Response.End实际上使用ThreadAbortException停止页面的执行。这里真正发生的是会话令牌在战斗中丢失。



Response.Redirect(View.aspx,false);不会中止线程,从而节省会话令牌。实际上,这个重载在RedirectFromLoginPage内部使用。



--Guru



I think the response.redirect ends the response. Response.End actually stops the execution of the page wherever it is using a ThreadAbortException. What happens really here is that the session token gets lost in the battle.

Response.Redirect("View.aspx", false); does not abort the thread and thus conserve the session token. Actually, this overload is used internally by RedirectFromLoginPage.

--Guru


尝试使用以下代码:

Try with following code:
Response.Redirect("View.aspx", false);



欲了解更多信息,请访问以下链接:

http://weblogs.asp.net/bleroy/archive/2004/08/03/Don_2700_t-redirect-after-setting-a-Session-variable-_2800_or-do-it-right_2900_.aspx [ ^ ]



http://stackoverflow.com/questions/699742/asp-net-session-value-not-changing [ ^ ]


这篇关于使用Session将动态值从一个ASP页面传递到另一个ASP页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆