使用 .ashx 的图像
我正在使用 .ashx 来检索图像,并将图像放置在 ajax 更新面板中,当将新图像添加到表单中时,它会检索图像,但当我们更改图像时,它不会更新图像,它甚至不会调用 .ashx 。 ashx 文件,但是当我刷新浏览器时它可以正常工作
i am using .ashx to retrive image and i place the the image inside the ajax update panel it retrive the image when a new image is added to the form but when we change the image it is not updating the image it dont even call the .ashx file but when i refresh the browser it works properly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来像是缓存问题。 尝试将此处找到的一些行添加到您的 ashx 文件中,它应该希望强制浏览器重新请求图像。 (我知道该链接适用于 ASP 而不是 ASP.NET,但 Response.Expires = -1 之类的内容应该有效)
或者,您可以更改 updatepanel 中图像的路径吗? 如果您只是在其末尾添加一个随机参数,浏览器会将其视为新请求(我们在执行此操作时使用当前日期/时间作为参数。该参数将被 ASP.NET 忽略,除非您明确引用它)
Sounds like a caching issue. Try adding some of the lines found here to your ashx file and it should hopefully force the browser to rerequest the image. (I know that the link is for ASP rather than ASP.NET, but things like Response.Expires = -1 should work)
Alternatively, can you change the path to the image in the updatepanel? If you just add a random parameter on to the end of it the browser will treat it as a fresh request (we use the current date/time as a parameter when we're doing this. The parameter is ignored by ASP.NET unless you explicitly reference it)
做这样的事情:
var sPath = "../../handlers/ProcessSignature.ashx?type=View&UserID=" + userID + "&d=" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
这会将 4 个字符的字母数字字符串放在查询字符串的末尾。 这不是必需的,但它会强制浏览器选择该图像的最新版本,因为 URL 不同。
我尝试了上面的方法,有些浏览器会忽略标题。 我把所有这些都扔进去了,Chrome/FireFox 3 没有尝试更新。
IE7有时能工作,
IE6只是摆弄拇指,问为什么它还存在。
更改上面的路径将在所有浏览器中修复它。
Do something like this:
var sPath = "../../handlers/ProcessSignature.ashx?type=View&UserID=" + userID + "&d=" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
That puts a 4 character alpha numeric string at the end of your query string. It's not needed, but it will force browsers to pick up the latest version of that image because the URL is different.
I tried the above and some browsers ignore the headers. I threw all of those in and Chrome/FireFox 3 didn't try to update.
IE7 worked sometimes
IE6 just twiddled it's thumbs and asked why it was still in existence.
Changing the path above will fix it in all browsers.