DotNetKick.com is an open-source project. Please report any bugs and let us know your great suggestions. Currently running svn revision 620 (rss)

Kick Spy!, Kick Zeitgeist and Kick Widgets

aquinas Subscribe to this feed
aquinas
Profile Kicked Submitted Comments Tags Friends Kicked By Friends Submitted By Friends


Comments:

Well, you stated that "There is more overhead associated with HTMTextWriter." That's why I included the timings, so that those who might wish to use your code were aware that their did not appear to be any significant overhead as far as time goes. If you meant some other overhead besides time, then sorry, my bad.
posted by aquinas 7 months, 5 days ago

try this:

System.Diagnostics.Stopwatch stopw = new System.Diagnostics.Stopwatch();
stopw.Start();

for (int i = 0; i < 1000; i++) {
System.Text.StringBuilder sb = new StringBuilder();
List<ElementAttribute> attributes = new List<ElementAttribute>();
attributes.Clear();
attributes.Add(new ElementAttribute(HTMLHelper.ID, "gallery"));
//attributes.Add(new ElementAttribute(HTMLHelper.CLASS, "\" <hello>blah</hello>"));
attributes.Add(new ElementAttribute(HTMLHelper.CLASS, "whatever"));
attributes.Add(new ElementAttribute("onclick", "whatever()"));

for (int j = 0; j < 1000; j++) {
sb.Append(HTMLHelper.BeginDiv(attributes));
sb.Append("blah");
sb.Append(HTMLHelper.EndDiv());
}
}

stopw.Stop();
Console.WriteLine(stopw.ElapsedMilliseconds);


stopw.Reset();
stopw.Start();
for (int i = 0; i < 1000; i++) {
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(sw);

for (int j = 0; j < 1000; j++) {
writer.AddAttribute(HtmlTextWriterAttribute.Id, "gallery");
//writer.AddAttribute(HtmlTextWriterAttribute.Class, "\" <hello>blah</hello>");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "whatever");
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "whatever()");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write("blah");
writer.RenderEndTag();
//string tstring = sw.GetStringBuilder().ToString();
}
}

stopw.Stop();
Console.WriteLine(stopw.ElapsedMilliseconds);

Console.ReadLine();

On my machine the version that uses HtmlTextWriter is about 300 milliseconds FASTER. If you uncomment out the lines that are commented out, it's about 100 ms slower. The reason why it's slower is because it properly esacapes HTML entities, which the HTMLHelperClass does not. That's what [)amien was referring to when he said your version is open to HTML injection.

I'm not trying to rail against you. I just take exception with your comment of "After reading these comments I am realizing that it is the tendency of most developers to over-complicate almost everything." It just seems a bit odd that you're saying people over complicate things, when there is an existing class that does what your class does, but you've invented your own. AND you have to tell people that use it to be careful because you need to do your own html escaping.
posted by aquinas 7 months, 5 days ago

Why not HtmlTextWriter?
posted by aquinas 7 months, 6 days ago

Microsoft's website doesn't say anything...
posted by aquinas 10 months, 26 days ago

Regarding making a round trip to the database: what kind of database would one be using that doesn't support identity fields or sequences that you have to make a round trip to the database to get the next id? Please tell me you're not doing a select max(id)+1 from table. Hello race conditions.

"Reason 3: Type/Table Ignorance" Yeah, now you also don't get any foreign key constraints / cascading deletes on your "ParentGUID".
posted by aquinas 11 months, 9 days ago

Movember! Mo Visual Studio!
posted by aquinas 11 months, 10 days ago

? Regions == Evil
False

Maybe he meant to assign Evil to Regions, rather than comparing them? =)
posted by aquinas 11 months, 14 days ago

Just databind in oninit.
posted by aquinas 11 months, 24 days ago

*blink*
posted by aquinas 1 year ago

The code is wrong.

It will not output

img src="http://www.nontalk.com/images/dot.gif, it will output img src="http://www.nontalk.com/mages/dot.gif because it says: match src|href followed by any character that is not h, t, or p. If the url started with h or t or p, the regex wouldn't match at all. I think he wanted a negative lookahead rather than a negated character class. E.g., (?!http)
posted by aquinas 1 year, 1 month ago
 

Sponsored Link: www.carlist.ie

Search:

Ads via The Lounge