March 2004 - Posts

Great Effective Forms Authentication Article

So now i was given the order to make my system have multiple roles lucky me they had to be static so i was thinking to use web.config but i didn't know how after searching on google for about a hour i found this great article Effective Forms Authentication, Part 1

Also the second article is great if you have multiple solutions Effective Forms Authentication, Part 2 hope you guy like it to because i think is a great couple of article's thanks Mike Gunderloy for the help :D

A potentially dangerous Request.Form value was detected from the client (TextBox1="")

I got this error when typing in <lalala> into a textbox and putting that onto a label.
And after following the dam advise i found out that i should put “ValidateRequest="false"” after “<%@ Page” and before “%>” in to the template.

To make sure that <lala> is printed into label and not the HTML <lala> i used HttpUtility.HtmlEncode(string) and now it works great.
For all the PHP guys use htmlspecialchars.

Javascript in ASP.NET

Yeah yet another problem over.
I was bizzy getting JavaScript working on a Web Control and I couldn’t find I a way to fix it so I went reading a the following article “Taking Full Control: Build Your Own Reusable Datalist with VS.NET” and I found this:
this.Attributes.Add("OnClick", string.Format("return confirm('{0}')",this.Confirmation));

With a bit of editing got the following stuff for one of my hyperlinks:
this.HyperLink1.Attributes.Add("OnClick","window.open(\"BrandAdd\");");
this.HyperLink1.Attributes.Add("onmouseover","document.getElementById(\"HyperLink1\").style.color=\"#008000\"");
this.HyperLink1.Attributes.Add("onmouseout","document.getElementById(\"HyperLink1\").style.color=\"#000000\"");
so now if you go over the hyperlink it will be green and if you go of off it it will turn black also if you click on it it will open a new window.

It is great and it work weee :P :)

What do people do at school

Hi all just a mayor off topic but i was at school making some movies on what we where doing and i think other people have to know how bizzy we are.

The movie's can be downloaded from: http://members.home.nl/warnar/school/ .
If you get a black screen you can download the divx codec here: http://download.divx.com/divx/DivX511.exe .

Hope you get the fun. Later

Plain javascript or ASP.NET??

So I have been writing for a while now and I’m just missing some functionality that I had with PHP and Javascript.

I know that I can use stuff like:
<INPUT type="button" value="Close" onclick="javascript:window.close()">
to close a page.
But I was wondering is there anyway to do this in ASP.NET code behind.

Or something like opening a popup windows with a size of 210 by 300 or something I know how to do it using javascript but it won’t work with webcontrol’s.

Thus I was wondering is there a way to get all this done in using ASP.NET and not plain javascript?

Validator Stress

So one again i was bizzy with a datalist and a user control and i was trying to get a validator to work. So I inserted a requiredfieldValidator but every time I pressed “Cancel” i needed to enter all the fields or if i pressed “edit”, this of course was a pain in the behind. So i had been trying to get just the Save button to work with a custom validator just validate on the server site but it all didn't work. So i finally after 6 hours found this nice property in the linkbutton's property CausesValidation and after I set this to false on the cancel and edit button and Now all works Great just Great.

Anyway I found it during a PHP lesson while i was bullying my teacher because I can program PHP better then him LOL.

 

Image Compression

Ok so after I got the cropping of a image done (see my log Cropping image) and had the “A generic error occurred in GDI+.” Error. By using:
using(Bitmap bitmap = new Bitmap(imageRigth))
{
 bitmap.Save(MapPath(fileName), imageRigth.RawFormat);
}

After that I was just uploading some picture for some more testing but the thing I was seeing was that the picture’s where 300 kb for just a 250x300 picture witch is large So I needed to get the stuff compressed here is how to do it.

First why is the picture saved now so big? Very easy it is saved as RawFormat (bmp).
How to save a compressed version this can be done like this:
public void Save(Stream, ImageCodecInfo, EncoderParameters);
So we have the stream witch is the image now for the “ImageCodecInfo”.
For the ImageCodecInfo I have the following function:
private static ImageCodecInfo GetEncoderInfo(string mimeType)
{
 ImageCodecInfo[] encoders;
 encoders = ImageCodecInfo.GetImageEncoders();
 for(int j = 0; j < encoders.Length; ++j)
 {
  if(encoders[j].MimeType == mimeType)
   return encoders[j];
 }
 return null;
}

You could get the jpg codec with "image/jpeg" as mimeType, “image/gif” for gif , “image/tiff” for tif or “image/png” for png.
That’s really it I never got the hang on what it exactly dues only that it go’s for the codec method that you put in.
Now for the EncoderParameters part this is the picture encoder , there can be multiple encoders in a “EncoderParameters“. I have the following function that I use for the encoder:
private static EncoderParameters Encode()
{
 EncoderParameters myEncoderParameters = new EncoderParameters();
 EncoderParameter myEncoderParameter = new EncoderParameter(Encoder.Compression,(long)EncoderValue.CompressionLZW);
 myEncoderParameters.Param[0] = myEncoderParameter;
 return myEncoderParameters;
}

It is also possible to get more then one encoder’s but why to do this is mostly a ? for me.

N00B DataAdapter Mistake

So I wanted to insert some info into a table and I was using:
sqlDataAdapterCategoryList.InsertCommand.Parameters["Titel"].Value = txt_titel;
sqlDataAdapterCategoryList.InsertCommand.Parameters["Description"].Value = txt_description;
sqlDataAdapterCategoryList.InsertCommand.ExecuteNonQuery();

And this worked perfect but when I wanted to get the info from the select that is included into the generated insert statement. So after trying to fill the dataset after the insert command execution I could get the entire last put in using:
ds.Categories[(ds.Categories.Count-1)]
Where ds is the dataset. But this seemed to be a wasted of data traffic so I needed something better so after trying some stuff for 30 min I went to my neighbor and hey showed me this:
DataSetCategory ds = new DataSetCategory();
Category db = new Category();
ds.Categories.AddCategoriesRow(Int32.Parse(ddl_parent.SelectedValue),txt_titel.Text,txt_description.Text);
sqlDataAdapterCategoryList.Update(ds);

So now I could insert the information and get the information using:
ds.Categories[0]
Without wasting resources or using a datareader or scalar