I have a very simple app here. It pulls a users picture from AD, saves it and then displayes it as an asp:Image. The program runs perfectly in the IDE but fails after I publish it and try to browse to it. Here's the code and the error.
Default.aspx code.
Code Behind: Default.aspx.vbCode:<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication3._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <asp:TextBox ID="TextBox1" runat="server" Width="247px"></asp:TextBox> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="Button" /> <p> <asp:Image ID="Image1" runat="server" Height="131px" Width="127px" /> </p> </asp:Content>
ERROR:Code:Option Strict On Imports System.DirectoryServices Imports System.IO Imports System.Drawing Public Class _Default Inherits System.Web.UI.Page Dim sSavePath As String = Nothing Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim strCN As String = TextBox1.Text Using Root As New DirectoryEntry 'Establish connection to current loged on users Active Directory Using Searcher As New DirectorySearcher(Root) 'Start at the top Searcher.Filter = "(&(objectCategory=user)(cn=" & strCN & "))" Searcher.SearchScope = SearchScope.Subtree 'Start at the top and keep drilling down Searcher.PropertiesToLoad.Add("thumbnailPhoto") 'Load picture Dim User = Searcher.FindOne 'Users contains our searh results If User.Properties.Contains("thumbnailPhoto") Then '<--This makes sure the property actually exists and has a value Dim bytBLOBData() As Byte = CType((User.Properties("thumbnailPhoto")(0)), Byte()) '<-- we need to use 0 here because this attribute only has one value Using stmBLOBData As New MemoryStream(bytBLOBData) 'Create new memory stream. Dim TempImg As System.Drawing.Image TempImg = System.Drawing.Image.FromStream(stmBLOBData) 'Load image from stream TempImg.Save(Server.MapPath("~/Images") + "\TempImg.jpg") 'save image to disk TempImg.Dispose() Image1.ImageUrl = ("~/Images/TempImg.jpg") Image1.AlternateText = "Users Picture" End Using Else Image1 = Nothing Image1.AlternateText = "NoPicture" End If End Using End Using End Sub End Class
What am I doing wrong?Code:Server Error in '/WebSite' Application. -------------------------------------------------------------------------------- A generic error occurred in GDI+. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [ExternalException (0x80004005): A generic error occurred in GDI+.] System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +800473 WebApplication3._Default.Button1_Click(Object sender, EventArgs e) in C:\Users\Robert.Kirchhof.000\Documents\Visual Studio 2010\Projects\WebApplication3\WebApplication3\Default.aspx.vb:23 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237




Reply With Quote
