-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhotoDisplay.ashx
executable file
·64 lines (55 loc) · 2.17 KB
/
PhotoDisplay.ashx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<%@ WebHandler Language="C#" Class="AspNet.StarterKits.Classifieds.Web.PhotoDisplay" %>
using System;
using System.Web;
using AspNet.StarterKits.Classifieds.BusinessLogicLayer;
namespace AspNet.StarterKits.Classifieds.Web
{
public class PhotoDisplay : IHttpHandler
{
public const string QueryStringFullSize = "full";
public const string QueryStringMediumSize = "medium";
public void ProcessRequest(HttpContext context)
{
HttpResponse Response = context.Response;
HttpRequest Request = context.Request;
int photoId = 0;
string photoIdQs = Request.QueryString["photoid"];
if (photoIdQs != null && Int32.TryParse(photoIdQs, out photoId))
{
// checking if a particular size was requested in the querystring (otherwise, small is default)
string sizeQs = Request.QueryString["size"];
PhotoSize size = PhotoSize.Small;
if (sizeQs != null)
{
if (sizeQs.Equals(QueryStringFullSize))
size = PhotoSize.Full;
else if (sizeQs.Equals(QueryStringMediumSize))
size = PhotoSize.Medium;
}
if (SiteSettings.GetSharedSettings().StorePhotosInDatabase)
{
byte[] photo = PhotosDB.GetPhotoBytesById(photoId, size);
if (photo != null)
{
Response.ContentType = "image/jpeg";
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.BufferOutput = false;
Response.OutputStream.Write(photo, 0, photo.Length);
}
}
else
{
string url = PhotosDB.GetFilePath(photoId, true, size);
Response.Redirect(url, true);
}
}
}
public bool IsReusable
{
get
{
return true;
}
}
}
}