Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old October 9th, 2007, 05:24 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Quote:
quote:Originally posted by Maxxim
One more thing:
Try to insert on your post message this:

http://www.sdfasdfasdf.com/sadfasdfa...shdfjklhasdjkf
interesting link - and here was me thinking that i was the ONLY one on the bottle :).

seriuosly tho' the avatar thing (imho) should be sorted with a 'standard' image size (server side image manipulation if required), so that you can worry less about css absolutes etc. however, on the flipside of this, wouldn't it be nice if the css accomodated any size of image, thereby rendering this discussion futile !!

as i said previously, 'we' need to get a few good 'css' enthusiasts onboard in a similar fashion to zengarden. after all, the template.master and css files follow a rigid pattern (in the basic tbh download), so it SHOULD be easy to allow designers to work with these predefined 'sticky' definitions to their hearts content.

anyway - just a few thoughts on a rainy sw scotland evening!!

jimi

http://www.originaltalent.com
  #12 (permalink)  
Old October 10th, 2007, 04:46 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Maxxim,

I have to admit I'm not a big fan of Javascript. It's certainly useful, but I missed the link misformatting info you just provided, so I definitely will implement that! Thanks heaps for that!

My reason for eventually picking my solution is that this way I programattically can reuse the same control, and using it for different purposes at different spots. Your code certainly would work for that as wel, but it'd be in the markup of the page (which I tend to try and stay away from if I can help it).

As for hosted images, I tend not to like those too much. The simple reasoning for that is that if the image dissappears on the original "host", it'll be gone from the profile as well. The site(s) my users use now uses the same principal, and while I certainly do not intend to start hosting every possible image they can chuck at me, with small profile pictures, it really shuld not be a major issue.

I've been trying to come up with a decent way to actually control hosting the pictures though, without requiring me to sell a kidney in order to pay for hosting space and bandwith for them. The most obvious choice would be to just create Google-groups, and keep creating new ones as the existing ones fill up, but perhaps others have better ideas? (Flickr maybe?).

Thanks again, Maxxim. I will definitely give your code a try.

Peter.

http://entropia-online.blogspot.com/
  #13 (permalink)  
Old October 10th, 2007, 05:06 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Peter,

in a word - Amazon S3. all the images on my site are hosted there and there's a great API which allows you to post the images as tho' posting to your own site. the only 'downside' is that you pay per gigabyte upload/download (i use an ashx handler to preserve as many in the host-server cache as possible). this is currently $0.15 per GB download, so my monthly bill has never been more than 1 US dollar :).

http://docs.amazonwebservices.com/Am...ef=get-started

if you setup an account, you can download c# /asp.net examples of it in use.



jimi

http://www.originaltalent.com
  #14 (permalink)  
Old October 10th, 2007, 05:20 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

oh one further 'nice' thing about S3. you can create a DNS CNAME entry on your site (in my case images.originaltalent.com) and 'point' that to s3.amazonaws.com. on S3, you then create a folder (or BUCKET as they call them)of the same name (images.originaltalent.com). bingo, the use of S3 then becomes transparent.

anyway - just my 10 cents worth ;)

jimi

http://www.originaltalent.com
  #15 (permalink)  
Old October 10th, 2007, 06:49 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Jim,

Thanks for that. I'm now looking into this. Could you elaborate a little more on this handler you use? How could I find more information on using something similar? (As an example, users at my site will regularly post pictures containing achievements they accomplished ingame, or screenshots of useful stuff they found, etc, so I'll most likely have to deal with a bit of data. Being able to cache images "younger" than 24 hours would definitely help out).

Also, if I would end up signing up for it, do you have some form of referal thingy? If so, I'll gladly credit you for it :)

Peter

http://entropia-online.blogspot.com/
  #16 (permalink)  
Old October 10th, 2007, 07:16 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Peter,

the handler i use basically downloads the image if it doesn't exist in the cache, otherwise, it pulls the cache image down. i'll drop off a copy of it somewhere for you to play with. it basically means that i both control the S3 bandwidth, as well as being able to optimise access to frequently used images.

don't know if there's a referal scheme or not, but if there is, then i'd be happy to accept any 'points' that it may confer!!

i'll drop a note of the location of the ashx handler a bit later on.

jimi

http://www.originaltalent.com
  #17 (permalink)  
Old October 10th, 2007, 07:22 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

ok, here it is:

<%@ WebHandler Language="C#" Class="ImageHandler" %>

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Web;
using System.Text;
using System.Net;
using System.Web.Caching;

public class ImageHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        bool succesfulImage = false;
        // Get the image ID from querystring, and use it to generate a cache key.
        String objectID = context.Request.QueryString["ObjectID"];
        //String cacheKey = context.Request.CurrentExecutionFilePath + ":" + objectID;
        String cacheKey = objectID;
        Byte[] imageBytes = null;

        if (objectID.Substring(objectID.LastIndexOf(".")) == ".flv")
        {
            context.Response.ContentType = "video/x-flv";
        }
        else
        {
            context.Response.ContentType = "image/jpeg";
        }

        // Check if the cache contains the image.
        Object cachedImageBytes = context.Cache.Get(cacheKey);
        if (cachedImageBytes != null)
        {
            try
            {
                imageBytes = (Byte[])cachedImageBytes;
                succesfulImage = true;
            }
            catch { succesfulImage = false; }
        }
        else
        {
            try
            {
                // Get image from uri (in ObjectID querystring),
                imageBytes = RequestGetMedia(objectID);
                // Store it in the cache (to be expired after 2 hours).
                // do the same cache.add in the file upload section
                // with the same key (i.e. the image url)
                // examine the cache timespan - is 2 hrs enough??
                context.Cache.Add(cacheKey, imageBytes, null,
                 DateTime.MaxValue, new TimeSpan(2, 0, 0),
                 CacheItemPriority.Normal, null);
                succesfulImage = true;
            }
            catch { succesfulImage = false; }
        }

        if (succesfulImage)
        {
            // Send back image.
            context.Response.Cache.SetCacheability(HttpCacheab ility.Public);
            context.Response.BufferOutput = true;
            context.Response.OutputStream.Write(imageBytes, 0, imageBytes.Length);
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    private byte[] RequestGetMedia(string TheURL)
    {
        Uri uri = new Uri(TheURL);
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
        Byte[] imageBytes = null;
        Encoding enc = Encoding.Default; //GetEncoding(1252); // Windows default Code Page

        try
        {
            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            request.Method = "GET";
            request.Proxy = WebRequest.DefaultWebProxy;

            //allow auto redirects from redirect headers
            request.AllowAutoRedirect = true;

            //maximum of 10 auto redirects
            request.MaximumAutomaticRedirections = 10;

            //60 second timeout for request
            request.Timeout = (int)new TimeSpan(0, 0, 60).TotalMilliseconds;

            //give the crawler a name.
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader readStream = new StreamReader(responseStream, enc);

            imageBytes = enc.GetBytes(readStream.ReadToEnd());
            responseStream.Dispose();
            readStream.Dispose();
        }
        catch (Exception ee)
        {
            // page = "Fail message : " + ee.Message;
        }
        return imageBytes;
    }
}

and to use it, just do this:

<img alt="a tooltip" src="ImageHandler.ashx?ObjectID=http://images.originaltalent.com/323cac00680947438e67f1d53bf648a5.JPG" />

or in code:

                        <div style="text-align: center">
                            <img src='<%# "ImageHandler.ashx?ObjectID=" + DataBinder.Eval(Container.DataItem,"ThumbURL") %>'
                                alt='' class="RotatorImage" onclick='showCallbackImage(this)' /><br />
                        </div>

good luck


jimi

http://www.originaltalent.com
  #18 (permalink)  
Old October 10th, 2007, 03:00 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

peter, one more thing re heavily trafficed forums. i occassionally frequent one of the financial bb's in the uk which is php (bespoke). this has no real facility to represent parents etc but is nonetheless very succesful and effective. i know what you mean tho about users having a preconceived idea of what a bb should contain, but sometimes, you've got to make up the (new) rules. also, the front page of this site has great (relevant) dashboard info. anyway, take a look yourself:

http://www.advfn.com/

jimi

http://www.originaltalent.com
  #19 (permalink)  
Old October 10th, 2007, 03:47 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

jimi,

Thanks for the wrapper class :) I'll definitely give it a go. And to give you an idea, the most active current forum about the game my site is also based on today, after about 2.5 years of being around, had it's 1 millionth post.

I have no insight into their bandwith and/or storage needs, but i can imagine them being big.

Should be interesting once we go live ;)

Peter

http://entropia-online.blogspot.com/
  #20 (permalink)  
Old October 15th, 2007, 01:40 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by Maxxim
For the other images in forums you can do one of two things:
by css like:

Code:
<div class="postContent">
<%# Eval("Message") %>
</div>

css:
.postContent{
width:445px; /* td width */
overflow:auto; 
word-wrap: break-word;
}
//this css lines are very usefull! Because if some user post an url with 100 characters without spaces, your design will be corrupted!
//overflow:auto;word-wrap: break-word; avoid that making an horizontal scroll just for that div!
Thanks for that :) Very helpful. The only trouble I'm trying to solve now is not setting the value of the width as hardcoded. What works for me might not work for someone with a different resolution, and the CenterCol is defined as dynamic...

Any clues if I can dynamically determine the width? (Not a CSS guru. Have to get me a book :p).

Thanks.

Peter

http://entropia-online.blogspot.com/
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS HELP:! CSS EXPANDIBLE BACKGROUND FOR TITLE phpuser2000 CSS Cascading Style Sheets 2 December 19th, 2007 12:36 AM
Rich's new CSS book: Beginning CSS 2nd Edition jminatel BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 0 June 15th, 2007 11:55 AM
help on forums dennisssss BOOK: ASP.NET Website Programming Problem-Design-Solution 1 February 4th, 2007 03:15 AM
Forums Help jsantamaria BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 August 28th, 2006 10:57 PM
more forums? MiltonBC Forum and Wrox.com Feedback 5 November 12th, 2004 03:15 PM



All times are GMT -4. The time now is 05:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.