Analyze ASP.Net Source Code with graspx

This series describes how to analyze ASP.Net source code. Follow the graspx category for more articles.

QueryString Parameters

To find out which query string parameters your pages are expecting, run:

graspx -col 1,5 l QueryStringField

Database Statements

To retrieve all SQL statements your application is issuing, use the following commands:

graspx -col 1,5 l SelectCommand
graspx -col 1,5 l InsertCommand
graspx -col 1,5 l UpdateCommand
graspx -col 1,5 l DeleteCommand

This also lists the aspx file name. If you want the SQL statements only, set the -col parameter to 5.

The output of these commands can be further analyzed to check whether the referenced tables and stored procedures are still in use.

graspx is available for download here.

Checking ASP.Net Source Code with graspx, part 2

In yesterday’s post about graspx, I demonstrated some usages of the tool that I originally had not thought of, and it soon turned out that Windows does not provide the necessary functionality (namely a unique option in the sort command).

Therefore I added two new switches to graspx:

-col selects which columns to appear in the output (implicitly sorting the generated output and filtering unique lines

-count adds a new column to indicate the number of occurrences of each line of the result

The following examples illustrate the simplifications of yesterday’s examples.

Check EmptyDataText

To retrieve the filename and the value of the EmptyDataText attribute, run:

graspx -col 1,5 l EmptyDataText

Check CSS references

To find all CSS classes referenced in aspx pages, run:

graspx -col 5 -count l CssClass
graspx -col 5 -count l class

With the new functionality it is much easier to retrieve relevant information from your source code.

graspx is available for download here.

Checking ASP.Net Source Code with graspx

In a recent post, I introduced graspx, a tool to check aspx source code files.

Let me show you some usages of this tool (usage requires that you cd to your web development directory):

Check XML compliance

Find all aspx files that are not XML-compliant:

graspx c -ce

Display all ascx files that are not XML-compliant

graspx c -ce *.ascx

Check page titles

To find all aspx files with no set page title, run

graspx l Title | find "Untitled Page"

Check EmptyDataText

If you copy and paste practice code reuse often, you may sometimes overlook changes in texts in the GUI which are not always displayed, such as GridView.EmptyDataText.

To retrieve list of all messages in EmptyDataText, run

graspx l EmptyDataText

To reduce the output to relevant information, namely filename plus text, add the for command (type “help for” for explanation):

for /f "usebackq delims=: tokens=1,5" %i in
  (`graspx l EmptyDataText`) do @echo %i: %j

Check CSS references

These procedures are useful if you want to clean up your CSS definitions:

Find all elements with inline styles:

graspx l style

Find all CSS styles referenced by your ASP.Net files:

graspx l class
graspx l CssClass
graspx l class *.master
graspx | CssClass *.master
graspx l class *.ascx
graspx | CssClass *.ascx

Get sorted results:

(for /f "usebackq delims=: tokens=5" %i in
  (`graspx l CssClass`) do @echo %i) | sort

Unfortunately, Windows sort lacks functionality to return unique results.

To be continued…

Introducing graspx

Every web developer needs to search source code every now and then. Tools like find, grep, or an IDE’s “Find” function can only search full text, without regard to context.

Since ASP.Net files (aspx, ascx) are XML-based, and should therefore be XML-compliant, an XML-aware tool searches more efficiently.

I have previously written about parsing XML/XHTML files with C# here and here.

Enter graspx (grep for aspx), a command-line tool to check and search any XHTML/XML-based files created in Visual Studio 2005.

As a first step, use graspx to check whether your files are XML-compliant. Unfortunately, files created with Visual Studio are not always strict XML, although VS2005 tends to be more compliant than VS2003.

   graspx c *.aspx
graspx c *.ascx
graspx c *.masterpage

graspx will report if files are not XML-compliant (missing closing tags, missing quotes for attribute values).

As all files are verified, you can

  • search for text occurrences in attribute values
  • list the values of a specific attribute

Invoking graspx without parameters will display the help text with all available commands and switches.

graspx can be downloaded here.