ASHX 处理程序;只触发一次
我有一个简单的 ASHX 处理程序,它返回动态生成的图像;图像是从自定义创建的类生成的,并且属于此类的对象使用 Session 传递给处理程序(我宁愿避免使用 QueryString)。
该处理程序用作 ASP 表单上图像的 URL,非常简单:一个下拉列表、一个按钮和一个图像。基本上,根据用户从列表中选择的内容,按下按钮后就会生成适当的图像。
开始时,实际图像的 Visible 属性设置为 false;我不希望处理程序在数据全部到位之前显示任何内容。
按下按钮后,将添加包含必要对象的所需会话参数,并使用 Server.Transfer 刷新页面。当 Page_load 方法检测到 Session 参数已正确设置时,它将图像上的 Visible 参数设置为 true。
之后,处理程序启动并生成图像。
到目前为止一切顺利...但是,如果用户现在从列表中选择不同的内容并按下按钮,尽管在会话中传递了正确的对象,但图像将不会更新。事实上,处理程序甚至不会启动(如果我在那里放置断点)。我需要关闭浏览器窗口并重新打开它才能正常工作。
任何想法可能是什么原因造成这种行为?
我怀疑答案很简单,我只是不知道有关 ASP(或处理程序)的一些基本知识......
I've got a simple ASHX handler that returns an dynamically generated image; the image is generated from a custom created class, and an object belonging to this class is passed to the handler using Session (I'd rather avoid using QueryString).
The handler is used as the URL of an image on a ASP form which is very simple: a drop down list, a button and an image. Basically, depending on what the user selects from the list, the appropriate image will be generated once the button is pressed.
At the start the actual image has it's Visible property set to false; I don't want the handler to display anything before the data is all there.
Once the button is pressed, the required Session parameter is added containing the necessary object, and the page is refreshed using Server.Transfer. When the Page_load method detects that the Session parameter has been correctly set, it sets the Visible parameter on the image to true.
After that the handler fires up and generates the image.
So far so good... However, if the user now picks something different from the list and presses the button, despite the correct object being passed in the Session, the image won't be updated. In fact, the handler won't even fire up (if I put a breakpoint in there). I need to close the browser window and reopen it for it to work.
Any ideas what could be the cause of such behaviour?
I suspect the answer is very simple, and I just don't know something fundamental about ASP (or handlers)...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该图像可能缓存在客户端上,并且浏览器不会费心从服务器请求新版本。在 ProcessRequest 方法的开头添加:
The image is probably cached on the client and the browser didn't bother to request a new version from the server. At the beginning of the
ProcessRequest
method add: