Checking NavigateUrls in ASP.Net

In previous posts, I wrote how you can analyze your ASP.Net application using graspx.

Now, I want to check whether the links in my aspx files point to existing files, i.e. the values of NavigateUrl and DataNavigateUrlFormatString must refer to existing filenames. This is achieved with a little shell magic:

@for /f "delims=?: tokens=1 usebackq" %f in
  (`graspx -count -col 5 l DataNavigateUrlFormatString *.aspx`) do
    @if not exist %f (echo %f does not exist)

The graspx command lists all XHTML elements with a DataNavigateUrlFormatString attribute. The for commands iterates through this list (rather, through the list of attribute values), and outputs a message if the referenced file does not exist. The “delims=?” option splits the URL arguments from the URL filename.

Use graspx with the f (find) parameter to find out which files are referencing the missing file.

The same operation can be used to identify wrong URLs or missing files for NavigateUrl:

@for /f "delims=?: tokens=1 usebackq" %f in
  (`graspx -count -col 5 l NavigateUrl *.aspx`) do
    @if not exist %f (echo %f does not exist)

Note that the NavigateUrl value may include a bind expression (Eval()), which is not handled separately in this example.

graspx is available for download here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.