i am developing an application which has an httphandler. This httphandler returns an image which is shown by the application. But in case, that my httphandler doenst return an image (if the user hasnt one) i want to use an url. But dont know how.
This is my code:
Imports System
Imports System.IO
Imports System.DirectoryServices
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Web
Imports System.Web.SessionState
Imports Microsoft.SharePoint
Imports System.Web.UI
Public Class GetImage
Implements IHttpHandler
''' <summary>
''' You will need to configure this handler in the web.config file of your
''' web and register it with IIS before being able to use it. For more information
''' see the following link: http://go.microsoft.com/?linkid=8101007
''' </summary>
#Region "IHttpHandler Members"
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
' Return false in case your Managed Handler cannot be reused for another request.
' Usually this would be false in case you have some state information preserved per request.
' Return False für SharePoint, true ist default
Return False
End Get
End Property
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim myimage As Byte() = DirectCast(user.Properties("uImage").Value, Byte())
If Not myimage Is Nothing Then
Dim mmStream As MemoryStream = New MemoryStream(myimage)
Dim img As Image = Image.FromStream(mmStream)
context.Response.Clear()
context.Response.ContentType = GetMimeType(img.RawFormat)
If GetMimeType(img.RawFormat).Equals("image/png") Or GetMimeType(img.RawFormat).Equals("image/bmp") Then
mmStream.WriteTo(context.Response.OutputStream)
Else
img.Save(context.Response.OutputStream, img.RawFormat)
End If
context.Response.End()
End If
End Sub
#End Region
End Class
ASP.NET Page:
myPhoto.ImageUrl = "~/GetImage.ashx?user=" & GetCurrentUser()
The line above thould be call GetImage.ashx?user=xxx and if there is no image for the user, i want to show a static placeholder image.
Yavuz B.
Member
5 Points
17 Posts
How to use URL when an HttpHandler is not returning an Image?
Dec 18, 2012 09:48 AM|LINK
Hi,
i am developing an application which has an httphandler. This httphandler returns an image which is shown by the application. But in case, that my httphandler doenst return an image (if the user hasnt one) i want to use an url. But dont know how.
This is my code:
Imports System Imports System.IO Imports System.DirectoryServices Imports System.Drawing Imports System.Drawing.Imaging Imports System.Web Imports System.Web.SessionState Imports Microsoft.SharePoint Imports System.Web.UI Public Class GetImage Implements IHttpHandler ''' <summary> ''' You will need to configure this handler in the web.config file of your ''' web and register it with IIS before being able to use it. For more information ''' see the following link: http://go.microsoft.com/?linkid=8101007 ''' </summary> #Region "IHttpHandler Members" Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get ' Return false in case your Managed Handler cannot be reused for another request. ' Usually this would be false in case you have some state information preserved per request. ' Return False für SharePoint, true ist default Return False End Get End Property Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim myimage As Byte() = DirectCast(user.Properties("uImage").Value, Byte()) If Not myimage Is Nothing Then Dim mmStream As MemoryStream = New MemoryStream(myimage) Dim img As Image = Image.FromStream(mmStream) context.Response.Clear() context.Response.ContentType = GetMimeType(img.RawFormat) If GetMimeType(img.RawFormat).Equals("image/png") Or GetMimeType(img.RawFormat).Equals("image/bmp") Then mmStream.WriteTo(context.Response.OutputStream) Else img.Save(context.Response.OutputStream, img.RawFormat) End If context.Response.End() End If End Sub #End Region End Class ASP.NET Page: myPhoto.ImageUrl = "~/GetImage.ashx?user=" & GetCurrentUser()The line above thould be call GetImage.ashx?user=xxx and if there is no image for the user, i want to show a static placeholder image.
best regards
yavuz
Neodynamic
Participant
988 Points
283 Posts
Re: How to use URL when an HttpHandler is not returning an Image?
Dec 18, 2012 02:07 PM|LINK
Add this to the Else part of your If:
Else context.Response.TransmitFile("YOUR_STATIC_IMAGE_FILE_HERE") End If