I created this script and called it "enable-compression.cmd":
cd c:\inetpub\adminscripts
cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoDynamicCompression true
cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression true
cscript adsutil.vbs set w3svc/Filters/Compression/GZIP/HcFileExtensions "txt" "css" "html" "htm" "js"
cscript adsutil.vbs set w3svc/Filters/Compression/GZIP/HcScriptFileExtensions "aspx" "asp"
iisreset /restart
Just in case any problems happened, I created "disable-compression.cmd":
cd c:\inetpub\adminscripts
cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoDynamicCompression false
cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression false
iisreset /RESTART
After you run these scripts, you restart IIS and watch as the performance benefits roll in.
To read more, Microsoft's Compression Article for IIS
| permalink | related link |




( 2.9 / 261 )Hi everyone,
One of my most heavily used bits of code is my CSVFile logic. I've updated this to handle a few unusual cases I've seen in the recent few months.
The code now allows you to provide the delimiter and text qualifier directly. Usually, the delimiter is the comma and the qualifier is the double-quote; but some files use different characters.
public static string[] ParseLine(string s, char delimiter, char text_qualifier)
{
List<string> list = new List<string>();
StringBuilder work = new StringBuilder();
for (int i = 0; i < s.Length; i++) {
char c = s[ i ];
// If we are starting a new field, is this field text qualified?
if ((c == text_qualifier) && (work.Length == 0)) {
int p2;
while (true) {
p2 = s.IndexOf(text_qualifier, i + 1);
// for some reason, this text qualifier is broken
if (p2 < 0) {
work.Append(s.Substring(i + 1));
i = s.Length;
break;
}
// Append this qualified string
work.Append(s.Substring(i + 1, p2 - i - 1));
i = p2;
// If this is a double quote, keep going!
if (((p2 + 1) < s.Length) && (s[p2 + 1] == text_qualifier)) {
work.Append(text_qualifier);
i++;
// otherwise, this is a single qualifier, we're done
} else {
break;
}
}
// Does this start a new field?
} else if (c == delimiter) {
list.Add(work.ToString());
work.Length = 0;
} else {
work.Append(c);
}
}
list.Add(work.ToString());
return list.ToArray();
}
| permalink | related link |




( 3 / 246 )Found this link which is amazingly useful for creating nifty tools.
http://www.rootsilver.com/2007/08/how-t ... solewindow
| permalink | related link |




( 2.9 / 266 )I didn't know this, and it's pretty useful to know!
"This is a regular string"
@"This is a string literal
This is the second line of the string literal, it includes a carriage return/linefeed."
@"This is a string literal
with ""Double Quotes!"". Isn't it cool?"
The third example produces a string literal with the words "Double Quotes!" in double quotes, exactly as you'd expect. Chalk one up for obvious features whose solution isn't as obvious as you might think.
| permalink | related link |




( 3 / 317 )So one of the business user decides that he needs to be able to press the enter key on a webform to submit. Specifically, during the login process. This kind of stuff is supposed to work by default, but when you're building a complex web app, sometimes you need more fine-grained control over the behavior of the enter key.
Here's a class I've created that allows you to specify the behavior of the enter key on all controls in your form.
EDIT: I've also added a fix for a case where you want to click a link rather than a button.
public class EnterKeyHandler
{
/// <summary>
/// When the user presses the "enter" key while control_to_watch has focus, call click on button_to_submit
/// </summary>
/// <param name="control_to_watch"></param>
/// <param name="button_to_submit"></param>
public static void ClickButtonOnEnter(WebControl control_to_watch, WebControl button_to_submit)
{
string js = @"
if (event.which || event.keyCode) {
if ((event.which == 13) || (event.keyCode == 13)) {
if ($get('@id@').href) {
eval($get('@id@').href);
} else {
$get('@id@').click();
}
return false;
}
} else {
return true;
}";
control_to_watch.Attributes.Add("onkeydown", js.Replace("@id@", button_to_submit.ClientID));
}
/// <summary>
/// When the user presses the "enter" key while control_to_watch has focus, set focus to next_focus
/// </summary>
/// <param name="control_to_watch"></param>
/// <param name="button_to_submit"></param>
public static void NextControlOnEnter(WebControl control_to_watch, WebControl next_focus)
{
string js = @"
if (event.which || event.keyCode) {
if ((event.which == 13) || (event.keyCode == 13)) {
$get('@id@').focus();
return false;
}
} else {
return true;
}";
control_to_watch.Attributes.Add("onkeydown", js.Replace("@id@", next_focus.ClientID));
}
| permalink | related link |




( 2.9 / 353 )Back Next

Calendar



