April 2012 Entries

Log JavaScript errors to the server.

Some time ago I found debugging - Automatic feedback on JavaScript error - Stack Overflow. and the discussion has links to Logging JavaScript Errors To ASP.NET(Unfortunately the link to download in the post is broken).and custom control to help log JavaScript errors by sending error information to the server -thecodepage.com/post/JavaS... downloaded solution from JSErrorNotifier.zip. When I wanted to include dll into my solution dependencies, I decided to rename WebControls.DLL ......

Case-insensitive Contains extension for list of strings

I wanted to have case-insensitive Contains method for list of strings.Overload Enumerable.Contains<TSou... Method (IEnumerable<TSource>, TSource, IEqualityComparer<TSourc... expects custom IEqualityComparer class.I was about to create my own class IgnoreCaseEqualityComparer : IEqualityComparer<string... then found StringComparer.Create Method, that allow to use standard class.public static bool ContainsString(this IEnumerable<string> collection, string toFind, bool ......

Select tool to minimize JavaScript and CSS size

There are multiple ways and techniques how to combine and minify JS and CSS files.The good number of links can be found in http://stackoverflow.com/qu... and in http://www.hanselman.com/bl... There are 2 major approaches- do it during build or at run-time.In our application there are multiple user-controls, each of them required different JS or CSS files, and ......

ReplaceBetweenTags function with delegate to describe transformation

I've created a function that allow to replace content between XML tags with data, that depend on original content within tag, in particular to MAsk credit card number.The function uses MidBetween extension from My StringHelper class /// <summary> /// /// </summary> /// <param name="thisString"></p... /// <param name="openTag"></para... /// <param name="closeTag"></par... /// <param name="transform"></pa... /// <returns></returns... ......

Code style Tip: Case insensitive string comparison

Goodif (String.Compare(myString, ALL_TEXT, StringComparison.OrdinalIgn... == 0) { return true; }OK(not obvious what true means) if (String.Compare(myString, ALL_TEXT, true) == 0) { return true; }BAD: (non null safe) if (myString.ToLower()==ALL_TE... { return true; } ......

Dump an arbitrary object To Html String

For debugging purposes me and my collegue wanted to dump details of the arbitrary object, and created function that uses LINQPad Dump functionality (thanks to http://stackoverflow.com/a/... and original http://linqpad.uservoice.co... discussion) public static string DumpToHtmlString<T>(this T objectToSerialize) { string strHTML = ""; try { var writer = LINQPad.Util.CreateXhtmlWri... ......

Disable messages from SQL Server “Login failed for user” in Event log

I’ve noticed multiple messages from SQL Server in EventLog on my machineLogin failed for user 'NT AUTHORITY\ANONYMOUS LOGON'. Reason: Token-based server access validation failed with an infrastructure error. Check for previous errors. [CLIENT: 10.222.25.129]I’ve found that there are machines of my co-workers, but they were not sure, which processes tried to access my SQL server.I’ve tried a few things and finally in SQL Server Configuration Manager disabled tcp, as it was suggested inhttp://blogs.msdn.com/b/p... ......

Specify Linq To SQL ConnectionString explicitly

When modifying Linq to Sql data model in Visual Studio 2010, it re-assigns ConnectionString that is available on developer’s machine. Because the name can be different on different machines, Designer often replace it with something like ConnectionString1, which causes errors during deployment.It requires developers to ensure that ConnectionString stays unchanged. More reliable way is to use context constructor with explicit ConnectionString name instead of parameterless default constructor GOOD: ......

Do not expose enum in WCF response

We had a backward compatibility problem in WCF client, when in Service application a new value was added to one of enums. We discussed different ways to avoid this backward compatibility issues, and I found recommendation do not expose enum in wcf response in http://stackoverflow.com/a/... is still required to create new versions of our service interfaces to replace each enum fields with string field, that expects only documented values, and describe, what should be default behavior, ......

Visual Studio 10 crashed when tried to open one of solutions

Visual Studio 10 crashed when I tried to open one of my solutions. Closing Visual Studio and rebooting the machine didn’t help.The error message that was logged(see below), didn’t give any useful ideas.Finally It was fixed after I’ve deleted MySolution.suo file, which was quite big, and also Resharper folders.Log Name: ApplicationSource: Application ErrorEvent ID: 1000Task Category: (100)Level: ErrorKeywords: ClassicUser: N/ADescription:Faulting application name: devenv.exe, version: 10.0.40219.1, ......

Translate jQuery UI Datepicker format to .Net Date format

I needed to use the same date format in client jQuery UI Datepicker and server ASP.NET code. The actual format can be different for different localization cultures.I decided to translate Datepicker format to .Net Date format similar as it was asked to do opposite operation in http://stackoverflow.com/qu... Note that replace command need to replace whole words and order of calls is importantFunction that does ......

«April»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345