HTTP GET Idempotence and ASP.NET

I am struck by the consequences of the experience Craig relates in this post:

http://staff.develop.com/candera/weblog2/CommentView.aspx?guid=54fd1ed8-ea12-4555-9ee3-4f9e3d57907e

He is discussing a Wiki site that mysteriously had its page content rolled back to a previous version.  Wiki pages generally contain a link to do this, and it is assumed that a human would follow it with caution.  Turns out that GoogleBot crawled the site and what-do-you-know the content rolled back.  The underlying problem was that a GET request caused a significant side effect, in this case altering the content of the linking page. 

The HTTP specification recommends that GET requests are idempotent, which means that a given action is performed once even if it invoked numerous times.  The intent is that GETs are “safe and repeatable”.  That is, it should be safe for a crawler to invoke any GET request (subject to authorization of course).  

This bears on the question of how to best use ASP.NET controls, notably the data controls where you might attempt to optimize ViewState by eliminating postbacks and changing buttons to hyperlinks.  Note that the LinkButton is safe because it causes a postback.  You can also probably get away with using a form with method=GET because a spider is unlikely to submit a form (even one based on GET), but I don't recommend it.

I traditionally replace postbacks with links to optimize ViewState, as opposed to “simply” disabling ViewState, because a race condition exists if you do not have a DataKeys collection that is consistent before and after the postback.  The race is that the resultset might have changed in the meantime, and the action would thus be carried out on the wrong data key.  That is, you would be operating purely by ordinal.  So, with this idempotence revelation I am back to square one with optimizing DataGrids.

This article is part of the GWB Archives. Original Author: Eron Wright

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.