Wednesday, December 05, 2007

When I first installed Windows Vista with IIS 7 I have started to notice that ASP.NET debugger tends to time-out very often. Previously I hadn't noticed such a behavior when I was using Windows 2003 with IIS 6. I really cannot tell if it was there or not, because I sometimes tend to dismiss this kind of issues if they are not very painful.

Sometimes however the debugger timeout IS painful. Fortunately the problem is easily solved. I have found the solution provided by jshallard on ASP.NET's forum:

In IIS 7 go to the Application Pools and select the Advanced Settings for the pool which you process runs in. In the Process Model section you can do one of two things;
    * Set the Ping Enabled property to False. This will stop IIS checking to see if the worker process is still running and keep your process alive permanently (or until you stop your debugged process)
    * If you prefer to allow IIS to continue the monitoring process then change the Ping Maximum Response Timeout value to something larger than 90 seconds (default value).

I've tried the second option and it worked.

Wednesday, December 05, 2007 7:06:45 PM (Central European Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [4]  | 

As hard as it is for me to believe, there are people out there that do not use the Total Commander! Yes, that is true. Those people use the built in Windows Explorer for navigating folders, copying files and all other things. Their main argument for doing it, is that "sometimes I may find myself in a situation where there is not Total Commander and I want to be prepared". Sometimes I also find myself in this kind of situation and what I find that I almost always miss is the ability to easily start a command line in a specified folder.

A typical situation is when there is some kind of application and it comes with a command line tools. In order to run those tools, we obviously need a command line - to display help text if nothing else. Without Total Commander, we are more or less forced to do a cd XXX few times.

More advanced users know the CMD command a little better and they just copy the folder path from the Explorer Window and do something like:

Start->Run->cmd /K cd XXX 

Where XXX is the path of the destination folder. This unfortunately not only requires a couple of steps, but also a few things to remember. The easier way is to make it possible to launch a command line by just selecting the right option from the context menu.

To make such an option available, just open Regedit.exe, navigate to:

HKEY_CLASSES_ROOT\Folder\shell

Create a new Key there, such as CmdHere. Set the value of a (Default) entry to some friendly text like "Cmd Here". Next, create a new command key and set the value of a (Default) entry to "cmd /K cd %1".

You should now be able to see a new option in the context menu, when you click on a folder.

Wednesday, December 05, 2007 6:58:14 PM (Central European Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 

There is a nice control in ASP.NET called ValidationSummary. Its purpose is to group and display all validation error messages in one place. Errors reported by Validator controls put on the page are displayed there. This is a standard way we all use ValidationSummary. Sometimes however, there is a need for presenting some kind of error found on the server side.

After investigation, I have found that there is no easy way of adding errors to the ValidationSummary. That is because the ValidationSummary control reads error messages directly from the page by means of iteration over all validators it gets by calling Page.GetValidators() method. Since none of the crucial methods is virtual, there is no way of customizing the standard behavior by means of inheritance.

This time rather than fighting/hacking ASP.NET once again, I've decided, to use it's own weapons against it. It came out as a rather clean solution. In order to add your error message to a ValidationSummary control you can add a validator to a Validators collection of the page. But which one to use? None of the standard ones since they all inherit from a Label (!?!?!).

It comes out, that ValidatorCollection's (that is the type of Validators property) Add method is one of those few .NET methods that operates using interfaces rather than concrete classes. This particular method accepts an IValidator interface. What we need then is a special CustomError class that looks like this:

public class CustomError : IValidator
{
    private string errorMessage;

    public CustomError(string errorMessage)
    {
        this.errorMessage = errorMessage;
    }

    public string ErrorMessage
    {
        get
        {
            return errorMessage;
        }
        set
        {
            throw new NotSupportedException();
        }
    }

    public bool IsValid
    {
        get
        {
            return false;
        }
        set
        {
            throw new NotSupportedException();
        }
    }

    public void Validate()
    { }
}

Now using this class is dead simple. Once we need to add an error to the summary, we do the following:

Validators.Add(new CustomError("Error Message"));

The only problem is that if the error is to persist between postbacks, we have to add the new validator every time.

Wednesday, December 05, 2007 6:40:47 PM (Central European Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [2]  |