Monday, July 18, 2011

Week picker using jQuery UI Datepicker

There is my implementation of Week picker using jQuery UI Datepicker (requers jQuery UI 1.8+).



Thursday, July 14, 2011

ASP.NET Web Pages and FormAuthentication.LoginUrl configuration

Recently I had integrated ASP.NET Web Pages into existing ASP.NET Web Forms site.
It was classic Web Forms project uses most of ASP.NET Web Forms features.

And of course it uses the built-in FormAuthentication. See Web.config:



Any time you access 'secure' url, you get redirected to Login.aspx with ReturnUrl parameter. This worked fine for years.

Sunday, July 10, 2011

ELMAH - Logging errors in ASP.NET

Catching and logging unhandled exceptions is one of the first tasks in developing an ASP.NET application.

Typically you put code which handles exceptions into Global.asax:

 


The are many ways to report an error: you may write it into a database, send an email or store it in memory.  I got tired of copying such code from one app to another and finally found a component that allows me to handle errors in a code-less way. It is ELMAH

Thursday, March 10, 2011

Mono's Gendarme

Gendarme is a extensible rule-based tool to find problems in .NET applications and libraries. Gendarme inspects programs and libraries that contain code in ECMA CIL format (Mono and .NET) and looks for common problems with the code, problems that compiler do not typically check or have not historically checked.

I ran this tool against my IZWebFileManager. The result was 1213 potential defects using 254 rules!:



Seems I have a lot of work here.

Monday, February 28, 2011

DateTime formatting in C#

I use a custom format to show DateTime to user: "dd/MM/yyyy".

var nowString = now.ToString("dd/MM/yyyy");

The reason, I use the custom formatting, is to be not depended on user regional settings.

So, no matter what user's locale is, I expect the same format for a date.

But today I found that it does not work as I expect. On one of the target machines I got "28.02.2011" instead of expected "28/02/2011".

Why slash (/) is replaced by dot (.)? Is format string not enough explicit?

I got the answer on MSDN (RTFM!): The slash (/) is not a literal, but a pattern for the default date separator defined in DateTimeFormatInfo.DateSeparator. It has to be escaped (leading with back slash (\)), for being reproduced literally.

I fix my format string to be @"dd\/MM\/yyyy"

var nowString = now.ToString(@"dd\/MM\/yyyy");

Now it works!

Sunday, February 27, 2011

Profiling NHibernate 3 application with NHProf

NHProf is a great too for profiling a NHibernate application. It is powerful and easy to use.

I used it for a long time, but recently I ran into troubles when I tried to capture DB queries in my newly started web application using NHibernate 3.0.

As many times before I downloaded latest NHibernate release, created a new web application, added a references to NHibernate.dll and all dependencies, added a reference to HibernatingRhinos.Profiler.Appender.dll and put a code, initializing NHProf - HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize(); in Application_Start.

Thursday, February 17, 2011

Microsoft's free tool for PHP development

It sounds ironical, but Microsoft really provides a great tool for web development supporting PHP.

Welcome WebMatrix!

At first look it is yet another tool to support the native Microsoft .NET technology. In fact I don't remember that Microsoft ever supported non their stuff.

But the world is changing and now WebMatrix is not only tool for .NET developing. With WebMatrix you can write a pure PHP web application! It is amazing! Isn't it?

In this post will show you how to start a new PHP web application with WebMatrix.