Maarten Balliauw {blog}

ASP.NET MVC, Microsoft Azure, PHP, web development ...

NAVIGATION - SEARCH

Excel, OpenXML and PHP

Yay! My new article on Excel, OpenXML and PHP has just been released in php|architect! A copy-paste action from http://www.phparch.com/issue.php?mid=102:

"A few months ago, Microsoft released Office 2007, a version of their office suite that generates open source documents. Here, Maarten Balliauw gives an overview of the history and the politics surrounding the release before moving on to introduce his PHPExcel project, an early adoption of Microsoft's OpenXML API that enables Excel 2007 spreadsheets to be generated with PHP."

ASP.NET 2.0 Event Validation

Event Validation is a new feature in ASP.NET 2.0 which provides an additional level of checks on postback actions. It verifies whether a postback from a control on client-side is really from that control and not from a malicious person trying to break your application.

Even if you forget to add security checks of your own, ASP.NET provides this functionality, because this feature is enabled by default. Sometimes, it is safe to turn this of, but Microsoft tries to have developers turn this of when they know what they are doing.

Unfortunately: I came across Event Validation… A user control on a master page convinced ASP.NET that a postback within that same user control was unsafe, resulting in the following error:

"Invalid postback or callback argument.  Event validation is
enabled using <pages enableEventValidation="true"/> in
configuration or <%@ Page EnableEventValidation="true" %>
in a page. For security purposes, this feature verifies that
arguments to postback or callback events originate from
the server control that originally rendered them.
If the data is valid and expected, use the
ClientScriptManager.RegisterForEventValidation method
in order to register the postback or callback data for validation."

There are some options to overcome this… One is to add a EnableEventValidation="false" in your @Page directive, another is to globally disable this in your Web.config (don’t!). The best solution, however, is telling ASP.NET to allow events from your user control’s inner controls, by adding the following snippet of code in the user control:

[code:c#]

protected override void Render(HtmlTextWriter writer)
{
    // Register controls for event validation
    foreach (Control c in this.Controls)
    {
        this.Page.ClientScript.RegisterForEventValidation(
                c.UniqueID.ToString()
        );
    }
    base.Render(writer);
}

[/code]

Team Foundation Server tools linkdump

Currently, I'm playing around with TFS (Team Foundation Server), and here's just a quick linkdump of some TFS tools, mainly on CodePlex. 

http://msdn2.microsoft.com/en-us/vstudio/aa718351.aspx#cipp
http://www.codeplex.com/TFSAdmin
http://www.codeplex.com/automation
http://www.codeplex.com/TFSCodeReviewFlow
http://www.codeplex.com/tfsconsole
http://www.codeplex.com/TfsPowerPack

Workaround for PHP file_exists on ZIP file contents

Recently, I was writing some PHP code, to check if a specific file existed in a ZIP file. PHP has this special feature called "stream wrappers", which basically is a system which enables PHP to do I/O operations on streams.

A stream can be a file, a socket, a SSH connection, ... Each of these streams has its own wrapper, which serves as an adapter between PHP and the underlying resource. This enables PHP to do, for example, a file_get_contents() on all sorts of streams.

Assuming regular PHP file functions would be sufficient, I coded the following:

[code:c#]

if (file_exists('zip://some_file.zip#readme.txt')) { ... }

[/code]

Knowing that the file readme.txt existed in the ZIP file, I was surprised that this function always returned false... What was even more surprising, is that a file_get_contents('zip://some_file.zip#readme.txt') returned readme.txt's data!

The reason for this is unknown to me, but I've written a (dirty) workaround that you can use:

[code:c#]

function zipped_file_exists($pFileName = '') {
    if ($pFileName != '') {
        $fh = fopen($pFileName, 'r');
        $exists = ($fh !== false);
        fclose($fh);

        return $exists;
    }

    return false;
}

[/code]

Scalable Apps with Asynchronous Programming in ASP.NET

A while ago, I posted about the DevDays, and some interesting sessions I took. One of these sessions was "Scalable Apps with Asynchronous Programming in ASP.NET", by Jeff Prosise. Searching the Internet, I found that Jeff also published an article on this subject on MSDN, which can be found on the following URL: http://msdn.microsoft.com/msdnmag/issues/07/03/WickedCode/default.aspx.