开发者

Some time an asp.net page is called and some time not

I am using a generateimage.aspx page which is used as an image source for an image.

When this page is called i am passing a querystring and then using a Session["abc"] var whoes value is being retruned as a jpg image.

The GenerateImage page is called from another page test.aspx like GenerateImage.aspx?text=P as image source under the img tag .And the value returned is then dislayed i the form of image.

PROBLEM: some time this page is called and some time not. Thus when the page is not called then the image value that is being returned is that which is assigned to the Session["abc"] var in previous Session.

Please let me know what might be the reason that the p开发者_运维问答age is called sometime and sometime not And how can I handle this problem.


I think this is a caching issue. By appending a timestamp or a random number to the end of the request url as a querystring will solve this.

Something like

GenerateImage.aspx?text=P&dynstr=" + (new Date()).getTime();


You can disable caching this way:

Response.Cache.SetExpires(DateTime.Now.AddDays(-1));


I agree with @pulse, HTML images are commonly cached by most browsers. So you have two options: 1. Append a random string to the source (not my favorite as it's just a hack) 2. Set the page to force no cache by setting a response header (much better IMO).

Another thing is that I would switch to a handler (ashx page) instead of a standard aspx page for image handling as it has a much lighter footprint/lifecycle and can be easily reused.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜