开发者

How to consume an asp.net image resizer with javascript

I use javascript/jquery to fill with html a web page. In IE works fine but in Firefox or Chrome the image is not shown wherever the image is shown when i click only the link:

http://localhost:12240/ImageResize.aspx?imgsrc=images/test.jpg&width=100

With javascript i create this html code:

<div class="item related-padding">
<div class="item-container item-0">
<div class="item-content" style="background:url(ImageResize.aspx?imgsrc=images/test.jpg&width=127) no-repeat;"></div>
<div class="item-type video"></div>
</div>
<div class="item-caption">Test</div>
</div>

I believe the problem is in C#, ASP.NET headers

Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "image/jpg";
Random random = new Random();
int random开发者_StackOverflow中文版Number = random.Next(1000000);
//Response.AddHeader("content-disposition", "attachment;filename=" + $randomNumber.ToString() + ".jpg");

/*resize happens here*/
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

Response.Flush();
Response.End();

bmp.Dispose();
image.Dispose();

any ideas?

All i want is to resize the image and output it as jpg


Add the <img src="ImageResize.aspx?imgsrc=images/test.jpg&width=127" alt=""/> instead of div with background image.


Your question misses the details needed for a to-the-point answer, but here are some hints you can look at:

  • Relative URIs in CSS are not always treated the same way, check with FireBug or an HTTP sniffer whether the correct relative URI is being retrieved. There used to be a difference here between IE and others, not sure it's still the same.

  • It's very likely that the error is in your JavaScript, which you don't show. You can check that with the javascript console and/or by printing out the result in an alert box or textbox and rendering that by hand, see what happens (look carefully at correct escaping).

  • You don't use an entity for the ampersand, though I can hardly imagine a browser would care about that

  • You don't do a Response.Clear(), which, if you create the response through a normal page request, can create a crippled response stream with headers and data from the page that you don't want there.

  • Test your code with a regular image on file, see if the CSS still holds (and the JavaScript, of course). Test JavaScript output and CSS separately to make sure to find the right guilty party (CSS, JS, server side C# or else).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜