error in GDI+

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; color:#333333; line-height:16px Im having problem running a site with security code in gif format
<span style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; color:#333333; line-height:16px own program created in win7 64x and doesnt have any runtime error but when it upload in win server 2003 it
has a runtime error: Generic error occured in GDI+
<span style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; color:#333333; line-height:16px The .net frameworks and VS versions are the same.
<span style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; color:#333333; line-height:16px Thanks in advance. The code follows:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections;
<span style="color:Blue; using System.Configuration;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Web;
<span style="color:Blue; using System.Web.Security;
<span style="color:Blue; using System.Web.UI;
<span style="color:Blue; using System.Web.UI.HtmlControls;
<span style="color:Blue; using System.Web.UI.WebControls;
<span style="color:Blue; using System.Web.UI.WebControls.WebParts;
<span style="color:Blue; using System.Xml.Linq;
<span style="color:Blue; using System.Data.SqlClient;

<span style="color:Blue; using System.IO;
<span style="color:Blue; using System.Text;

<span style="color:Blue; using System.Drawing.Text;
<span style="color:Blue; using System.Drawing.Imaging;
<span style="color:Blue; using System.Security.Cryptography;
<span style="color:Blue; using System.Drawing;

<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class nobatdehi2 : System.Web.UI.Page
{
<span style="color:Blue; string CreateSalt()
{
Random r = <span style="color:Blue; new Random();
<span style="color:Blue; return r.Next(10000, 99999).ToString();
}

<span style="color:Blue; private <span style="color:Blue; string GenerateCode()
{
Random r = <span style="color:Blue; new Random((<span style="color:Blue; int)DateTime.Now.Millisecond);
<span style="color:Blue; int maxNumber = 0;
<span style="color:Blue; int numberCodeQuantity = 0, alphabeticCodeQuantity = 0;
<span style="color:Blue; string code = String.Empty;

maxNumber = r.Next(6, 7);
numberCodeQuantity = 1;

alphabeticCodeQuantity = maxNumber - numberCodeQuantity;

<span style="color:Blue; for (<span style="color:Blue; int i = 1; i <= numberCodeQuantity; ++i)
{
code += ((<span style="color:Blue; char)r.Next(48, 57)).ToString();
}
<span style="color:Blue; for (<span style="color:Blue; int i = 1; i <= alphabeticCodeQuantity; ++i)
{
code += ((<span style="color:Blue; char)r.Next(65, 90)).ToString();
}
<span style="color:Blue; return code;
}

<span style="color:Blue; string CreateImage(<span style="color:Blue; string path, <span style="color:Blue; int height, <span style="color:Blue; int width)
{
Random r = <span style="color:Blue; new Random();
<span style="color:Blue; string salt = GenerateCode();
Bitmap bmp = <span style="color:Blue; new Bitmap(width, height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmp);
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.Clear(Color.White);
System.Drawing.Drawing2D.Matrix mymat = <span style="color:Blue; new System.Drawing.Drawing2D.Matrix();
<span style="color:Blue; int i;

<span style="color:Blue; for (i = 0; i < salt.Length; i++)
{
mymat.Reset();
mymat.RotateAt(r.Next(-30, 0), <span style="color:Blue; new PointF(width * (0.12f * i), height * 0.5f));
g.Transform = mymat;
g.DrawString(salt.ToString(), <span style="color:Blue; new Font(<span style="color:#A31515; "Comic Sans MS", 16, FontStyle.Italic),
Brushes.Brown, width * (0.15f * i), height * 0.5f);
g.ResetTransform();
}

bmp.Save(path, ImageFormat.Gif);
g.Dispose();
bmp.Dispose();
g.Dispose();
bmp.Dispose();
<span style="color:Blue; return salt;
}

<span style="color:Blue; protected <span style="color:Blue; void Page_Load(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (!Page.IsPostBack)
{
<span style="color:Blue; string salt = CreateImage(Server.MapPath(<span style="color:#A31515; @"temp/") + <span style="color:#A31515; "temp.gif", 60, 100);
Image1.ImageUrl = <span style="color:#A31515; "temp/temp.gif";
Session[<span style="color:#A31515; "salt"] = salt;
}
}
<span style="color:Blue; protected <span style="color:Blue; void Button1_Click(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; try
{
<span style="color:Blue; string ses = Session[<span style="color:#A31515; "salt"].ToString();
<span style="color:Gray; ///<span style="color:Green; ////////////////////////////////////////////////////////////////////////
<span style="color:Blue; if (txtSecurityImage.Text.ToLower() == ses.ToLower())
{



<span style="color:Blue; string TrackID = DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
Label2.Text = TrackID;

SqlConnection conn = <span style="color:Blue; new SqlConnection(<span style="color:#A31515; @"Data Source=.;AttachDbFilename=F:App_Databazdid.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = <span style="color:Blue; new SqlCommand(<span style="color:#A31515; "select SUM(h) as jam from bazdid where ruz=@ruz and mah=@mah and saat=@saat ", conn);
SqlParameter[] parm1 = <span style="color:Blue; new SqlParameter[3];
parm1[0] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@ruz", System.Data.SqlDbType.NVarChar);
parm1[0].Value = DropDownList2.Text;
parm1[1] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@mah", System.Data.SqlDbType.NVarChar);
parm1[1].Value = DropDownList3.Text;
parm1[2] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@saat", System.Data.SqlDbType.NVarChar);
parm1[2].Value = DropDownList4.Text;
conn.Open();
cmd.Parameters.AddRange(parm1);
SqlDataReader dr = cmd.ExecuteReader();
<span style="color:Blue; bool mojaz = <span style="color:Blue; false;
<span style="color:Blue; if (dr.Read())
{
<span style="color:Blue; if (dr[<span style="color:#A31515; "jam"] == DBNull.Value)
mojaz = <span style="color:Blue; true;
<span style="color:Blue; else
<span style="color:Blue; if (<span style="color:Blue; decimal.Parse(dr[<span style="color:#A31515; "jam"].ToString()) < 200)
mojaz = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
mojaz = <span style="color:Blue; true;
}
dr.Close();
<span style="color:Blue; if (mojaz)
{
SqlCommand comm = <span style="color:Blue; new SqlCommand(<span style="color:#A31515; "Insert into bazdid(a,b,c,d,e,f,g,h,ruz,mah,saat,kod)values(@a,@b,@c,@d,@e,@f,@g,@h,@ruz,@mah,@saat,@kod) ", conn);
SqlParameter[] parm = <span style="color:Blue; new SqlParameter[12];
parm[0] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@a", System.Data.SqlDbType.NVarChar);
parm[0].Value = TextBox1.Text;
parm[1] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@b", System.Data.SqlDbType.NVarChar);
parm[1].Value = TextBox2.Text;
parm[2] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@c", System.Data.SqlDbType.NVarChar);
parm[2].Value = TextBox3.Text;
parm[3] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@d", System.Data.SqlDbType.NVarChar);
parm[3].Value = TextBox4.Text;
parm[4] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@e", System.Data.SqlDbType.NVarChar);
parm[4].Value = DropDownList1.Text;
parm[5] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@f", System.Data.SqlDbType.NVarChar);
parm[5].Value = TextBox5.Text;
parm[6] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@g", System.Data.SqlDbType.NVarChar);
parm[6].Value = TextBox6.Text;
parm[7] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@h", System.Data.SqlDbType.Int);
parm[7].Value = TextBox7.Text;
parm[8] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@ruz", System.Data.SqlDbType.NVarChar);
<span style="color:Blue; if (DropDownList6.Enabled == <span style="color:Blue; true)
{ parm[8].Value = DropDownList6.Text; }
<span style="color:Blue; if (DropDownList2.Enabled == <span style="color:Blue; true)
{ parm[8].Value = DropDownList2.Text; }
<span style="color:Blue; else
{ parm[8].Value = DropDownList2.Text; }
parm[8].Value = DropDownList2.Text;
parm[9] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@mah", System.Data.SqlDbType.NVarChar);
parm[9].Value = DropDownList3.Text;
parm[10] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@saat", System.Data.SqlDbType.NVarChar);
<span style="color:Blue; if (DropDownList4.Visible == <span style="color:Blue; true)
{ parm[10].Value = DropDownList4.Text; }
<span style="color:Blue; else
{ parm[10].Value = DropDownList5.Text; }


parm[11] = <span style="color:Blue; new SqlParameter(<span style="color:#A31515; "@kod", System.Data.SqlDbType.NVarChar);
parm[11].Value = Label2.Text;
comm.Parameters.AddRange(parm);
comm.ExecuteNonQuery();
conn.Close();
Label1.Visible = <span style="color:Blue; true;
Label3.Visible = <span style="color:Blue; true;
Label2.Visible = <span style="color:Blue; true;
Button1.Visible = <span style="color:Blue; false;
Label4.Visible = <span style="color:Blue; false;
}
<span style="color:Blue; else
{
Label4.Visible = <span style="color:Blue; true;
Label1.Visible = <span style="color:Blue; false;
Label2.Visible = <span style="color:Blue; false;
Label3.Visible = <span style="color:Blue; false;

}
<span style="color:Blue; return;

}
<span style="color:Blue; else { Label5.Text = <span style="color:#A31515; "Input code is wrong"; }
}
<span style="color:Blue; catch { Label2.Text = <span style="color:#A31515; "Error : cannot connect to database,please try again later";
Label2.Visible = <span style="color:Blue; true;
}




}
[/code]
<br/>


<span style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; color:#333333; line-height:16px <br/>


View the full article
 

Similar threads

A
Replies
0
Views
171
ANIL AYDINALP
A
D
Replies
0
Views
110
Donald Uko
D
A
Replies
0
Views
129
Abdurrahman Nurhakim
A
Back
Top