Reputation: 143
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 page is called sometime and sometime not And how can I handle this problem.
Upvotes: 2
Views: 97
Reputation: 4500
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.
Upvotes: 0
Reputation: 40641
You can disable caching this way:
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Upvotes: 0
Reputation: 187070
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();
Upvotes: 3