Doing Web-Based Standards Validation

There are a lot of sites, especially W3C that provides site-wide validation. On the other side, are web sites that require logons or internal only – never the twain can meet. Or can they?

 

I have a reasonable solution:

  • To Web.Config, add an AppSetting “StandardsReview” that indicates if this site is in review mode.
  • Automate things like logins with a specific account if any page is called and the user is not logged in.
    • I use Master Pages, so this is an easy.
  • Put an if/else around any code that you want to protect from accidental calls. Since you are using a specific account above – the account may be a safe testing-account and this coding is not needed. It really should be such a safe account.

The following assumes that the validators will walk all of the links from the home page. On the home page I drop this simple code:

<div style="display: none">
    <uc:SiteValidationSitemap runat="server" ID="SiteValidation" Visible="false" />
</div>

Note that it is hidden visually and defaults to be not visible. If you are in StandardsReview, then Visible is set to true.

 

What is in this user control? The page is trivial:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="StandardValidationSiteMap.ascx.cs" Inherits="StandardValidationSiteMap" %>
<asp:Panel runat="server" ID="HRefLinks" />

 

And behind the scene we have:

public partial class StandardValidationSiteMap : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HyperLink hl;
        DirectoryInfo di=new DirectoryInfo(Server.MapPath("~/"));
        foreach(FileInfo fi in di.GetFiles("*.aspx", SearchOption.AllDirectories))
        {
            HRefLinks.Controls.Add(hl=new HyperLink(){Text=fi.Name, Visible=true});
            hl.NavigateUrl=String.Format("~/{0}", fi.FullName.Substring(di.FullName.Length));
        }
    }
}

What do we get? In normal operation:

<div style="display: none">
</div>

and in StandardsReview every page is listed:

<div style="display: none">
    <div id="SiteValidation_HRefLinks">
        <a href="Account.aspx">Account.aspx</a>
        <a href="Account.Deposit.aspx">Account.Deposit.aspx</a>
        <a href="Account.Deposit.Confirmation.aspx">Account.Deposit.Confirmation.aspx</a>
    </div>
</div>
 

Now we can just expose the website on the real internet.  Set up IIS to run this site. If you are like me, with a dynamic IP address,  then just find that address and prefix it to the address and test away. Some of my favorite validation tools are:

At the extreme case for an internal system – you can likely VPN into it and then by doing port forwarding, you can expose it for validation (just don’t IT Security about what you are doing….)

Comments

Popular posts from this blog

Yet once more into the breech (of altered programming logic)

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

How to convert SVG data to a Png Image file Using InkScape