English 中文(简体)
Fancybox not showing streamed image correctly
原标题:

I ve got an aspx page that streams jpeg s. It sets the content type and then writes to the response stream. If I view the images directly they work a treat, but if I use fancybox 1.2.6 I get the following. alt text

Using fancybox 1.2.1 the images do show.

Here is the code that is pushing out the image.

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (Image outImg = Image.FromStream(responseStream))
                {
                    Response.Clear();
                    Response.ContentType = "image/jpeg";
                    outImg.Save(Response.OutputStream, ImageFormat.Jpeg);
                }
            }
        }

Any help?

最佳回答

There is a regular expression inside the fancybox script file that needed to be amended in order for it to allow that file extension to be treated correctly.

imageRegExp = /.(aspx|jpg|gif|png|bmp|jpeg)(.*)?$/i;

I ve just added aspx for now, but will need to do some additional work in order to make it function correctly.

问题回答

Our images also didn t have extensions and were just emitted from an ashx handler.

We ended up adding type : image to the fancybox declaration like:

$( .fb1 ).fancybox({ titlePosition : inside , type : image })

Which worked perfectly.

See point 6 in the Fancybox FAQ:

FancyBox gueses content type from url but sometimes it can be wrong. The solution is to force your type, like so - $(".selector").fancybox({ type : image });

(required version 1.3+)

Can we see your server-side code that publishes the content? It appears the content-type is not set properly or was set before the point where you output your data. You may want to try a Response.Clear() before outputting your new content-type. ( Your browser may be assuming the content type when opening it directly )





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签