Tools – Roy Osherove – Regulazy!

Just found an awesome tool allowing Regex noob’s such as myself, to build up Regex patterns, using only the sample data that you wish to match- go download Regulazy here!

Tools – Roy Osherove – Team Leadership, Agile Development & .NET – Speaking, Consulting, Training and Tools.

No Comments

How to run SQL Profiler against local SQL Express instances

I’m building a project using entity framework and wanted to ensure it wasn’t going mental and spamming the database with more queries than it should- this requires SQL Profiler, but i didn’t know how to connect it to my local instance of sql (I had just added an MDB file to the app’s app_data folder, so it was running via local sql express)

Turns out it’s easy- you just connect to .\SQLEXPRESS database and then execute this query against the master database;

SELECT
owning_principal_name,
instance_pipe_name
FROM
sys.dm_os_child_instances

From the results you will be able fish out the “named pipe” that you can just put into the server name box when connecting with profiler.

Sql Profiler connection dialogue

Sql Profiler connection dialogue

via Brad Wilson: Profiling SQL Server Express User Instances.

, ,

No Comments

Properties getting “k__BackingField” appended to their name in the WSDL file

I was finding k__backingField was being appended to all my object properties when exposed via my a WCF service, in the WSDL.  The solution it turns out was simple- just had to make my class a [DataContract] and mark the properties as [DataMember].

via WCF Data Contracts and “k__BackingField” Property Naming – Nathan Bridgewater.

No Comments

Making your WCF Service compatible with legacy .net 1.1 applications

I’m building an error tracking service which all our future web project will report to, so we can track and tag all our various systems problems from one place- this is currently done with email which is a bit of a nightmare!

According to Microsoft, traditional ASMX web services are now considered “Legacy technology” (!) so I thought I would buite the bullet and build the new services using WCF.

This was fairly painless until I tried to consume the web service in some old .net 1.1 web apps- when trying to add the web reference I received this error message;

Web ReferenceslocalhostReference.map(1): Custom tool warning: DiscoCodeGenerator unable to initialize code generator.  No code generated.

I found a great article over on the MSDN – and all it takes is a small change to the web.config, fiddling with, my old friend, the httpBindings.

I had to swap out the default bindings put in by .net;

        <endpoint address="" binding="wsHttpBinding" contract="HachetteErrorTracker.IErrorLog">
					<identity>
						<dns value="localhost"/>
					</identity>
				</endpoint>

For this one;

<endpoint
           address=""
           binding="basicHttpBinding" bindingNamespace="http://errortracker.localhost/"
           contract="HachetteErrorTracker.IErrorLog"
        />

How to: Configure WCF Service to Interoperate with ASP.NET Web Service Clients.

No Comments

Giving Umbraco custom tree’s children!

This was something i was looking for for a while- turns out it is buried deep in their forums;

As shown in their own example (I’ve reblogged here incase the page ever moves or dissapears!!)

Turns out it’s just a case of setting the “source” property of the XmlTreeNode.

public override void Render(ref XmlTree tree)
{

            Dictionary.DictionaryItem[] tmp;
        //this.id is set when the tree.aspx creates this object.
        //It is the nodeID that is passed in via the tree service parameters (i.e. the query string)
        //this checks if the id is the StartNodeID (root node), if it’s not then this will
        //look up the child nodes for the current dictionary item.
            if (this.id == this.StartNodeID)
                tmp = Dictionary.getTopMostItems;
            else
                tmp = new Dictionary.DictionaryItem(this.id).Children;

            foreach (Dictionary.DictionaryItem di in tmp)
            {
             XmlTreeNode xNode = XmlTreeNode.Create(this);
             xNode.NodeID = di.id.ToString();
             xNode.Text = di.key;
             xNode.Action = string.Format("javascript:openDictionaryItem({0});", di.id);
             xNode.Icon = "settingDataType.gif";
             xNode.OpenIcon = "settingDataType.gif";
             //if there is no children, then set the source to an empty string
//this will ensure that there is no expand button for this node when it is
//rendered. Otherwise, set the source to the tree service url by using
//the BaseTree’s GetTreeServiceUrl method
             xNode.Source = di.hasChildren ? this.GetTreeServiceUrl(di.id) : "";
             tree.Add(xNode);
            }
}

3 Comments

Whats the definitive maximum size of an email address?

I’ve written lots of app’s which store email addresses, and usually go for a nvarchar(100) to store them, but thought I would find out once and for all, what the actual maximum size was- just out of curiousity.

Having googled around, I came across a couple of lengthy posts on the matter (here and here), quoting figures from various standard (which seemed to point at 320 character), then corrections to those standards by members of ICANN based on the SMTP spec and so on and so forth…

After much trawling, it seems the official answer is : 254 characters (256 including the standard <> brackets around the address)

, ,

2 Comments

Umbraco Installation – folder permissions setup

Just a real quick batch script i knocked up which sets the appropriate permissions to the various folders in the root of a fresh umbraco install- just drop this into a batch file, and run it from the root of your umbraco install;

REM 2009.10.22 SY - Set permissions- user/ folders from "Install Umbraco 4 on Windows Vista" guide
icacls app_code /grant "Network Service":(OI)(CI)(F)
icacls bin /grant "Network Service":(OI)(CI)(F)
icacls config /grant "Network Service":(OI)(CI)(F)
icacls css /grant "Network Service":(OI)(CI)(F)
icacls data /grant "Network Service":(OI)(CI)(F)
icacls masterpages /grant "Network Service":(OI)(CI)(F)
icacls media /grant "Network Service":(OI)(CI)(F)
icacls python /grant "Network Service":(OI)(CI)(F)
icacls scripts /grant "Network Service":(OI)(CI)(F)
icacls umbraco /grant "Network Service":(OI)(CI)(F)
icacls usercontrols /grant "Network Service":(OI)(CI)(F)
icacls xslt /grant "Network Service":(OI)(CI)(F)
pause

No Comments

Command line Batch File to Remove Direcories, using a Wild Card!

We have a bunch of web services which log details of requests that come in, in folders named using the current date- in the format YYYY-MM-DDD-HH-MM-SS. I wanted to produce a simple cleanup batch file which we could run every month to bin all logs for transactions which happened 3 months ago- using the dos commands which exist on Windows Server 2003.

The dos “del” command allows you to delete using wild cards – so for example “dev 2009-07-*” would erase any files starting with “2009-07-”; However this doesn’t work with folders- so it fell to the rd (remove directory) command- but this doesn’t support wild cards (I’m assuming for safety- to stop you permanently erasing 100’s of folders and their contents accidently- remember there’s no recycle bin when you delete from the command line!).

To get around this I created a simple Batch file which accepted a wildcard as a parameter, then removes all those folders at the current level (it wont check recursivly). Just in case this is of use to anyone else, here’s the code;

REM - performs a remove directory, with wildcard matching - example ; rd-wildcard 2007-*
dir %1 /b >loglist.txt
setlocal enabledelayedexpansion
for /f %%a in (./loglist.txt) do (
	rd /s /q %%a
)
del /q loglist.txt
endlocal

2 Comments

Paged List of Child Nodes in Umbraco

We just started looking at Umbraco- and so I’m delving into Macro’s – these are the packaged up chunks of functionality which make your site actually do things and either take the form of XSLT files which process and spit out the contents of your database, or dot net controls.

I found an excellent example XSLT that allows you to create a paginated list of child nodes over on Tim Geyssens “nibble” blog, and I’ve modified it ever so slightly to stop the numerical index rendering if the pagecount is less than 2- so thought I would re-post it!


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&amp;amp;amp;#x00A0;">
]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">

  <xsl:output method="xml" omit-xml-declaration="yes"/>
  <xsl:param name="currentPage"/>
  <xsl:template match="/">

    <xsl:variable name="recordsPerPage" select="/macro/recordsPerPage"/>
    <xsl:variable name="pageNumber" >
      <xsl:choose>
        <!-- first page -->
        <xsl:when test="umbraco.library:RequestQueryString('page') <= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">0</xsl:when>
        <!-- what was passed in -->
        <xsl:otherwise>
          <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
        </xsl:otherwise>
      </xsl:choose>

    </xsl:variable> &amp;amp;amp;nbsp;

    <xsl:variable name="numberOfRecords" select="count($currentPage/node)"/>

    <!-- The fun starts here -->
    <ul>
      <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <xsl:if test="position() > $recordsPerPage * number($pageNumber) and
position() <= number($recordsPerPage * number($pageNumber) +
$recordsPerPage )">
          <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:value-of select="@nodeName"/>

            </a>
          </li>
        </xsl:if>
      </xsl:for-each>
    </ul>

    <xsl:if test="$pageNumber > 0">
      <a href="?page={$pageNumber -1}">previous </a>
    </xsl:if>

<xsl:if test="($numberOfRecords > $recordsPerPage)">
    <xsl:call-template name="for.loop">
      <xsl:with-param name="i">1</xsl:with-param>
      <xsl:with-param name="page" select="$pageNumber +1"></xsl:with-param>
      <xsl:with-param name="count" select="ceiling(count($currentPage/node)div $recordsPerPage)"></xsl:with-param>
    </xsl:call-template>
</xsl:if>

    <xsl:if test="(($pageNumber +1 ) * $recordsPerPage) < ($numberOfRecords)">
      <a href="?page={$pageNumber +1}">next</a>
    </xsl:if>
  </xsl:template>

  <xsl:template name="for.loop">

    <xsl:param name="i"/>
    <xsl:param name="count"/>
    <xsl:param name="page"/>
    <xsl:if test="$i <= $count - 1">

      <xsl:if test="$page != $i">
        <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i - 1}" >

          <xsl:value-of select="$i" />
        </a>
      </xsl:if>

      <xsl:if test="$page = $i">

        <xsl:value-of select="$i" />

      </xsl:if>
    </xsl:if>
    <xsl:if test="$i <= $count - 1">
      <xsl:call-template name="for.loop">
        <xsl:with-param name="i">
          <xsl:value-of select="$i + 1"/>
        </xsl:with-param>
        <xsl:with-param name="count">
          <xsl:value-of select="$count"/>
        </xsl:with-param>
        <xsl:with-param name="page">
          <xsl:value-of select="$page"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

2 Comments

Stop the “web.config” being inherited by child applications in sub folders

We recently had an issue setting a .net microsite live off the back of an existing domain, hosting another .net site.

This was due to the web.config being inherited to the child- we would be hit with errors like this;

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load file or assembly ‘UrlRewritingNet.UrlRewriter’ or one of its dependencies. The system cannot find the file specified. (d:ProjectsVSAspDotNetFaqProjectWebsiteweb.config line 89)

Source Error:

Line 88: <httpModules>
Line 89:   <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule,
      UrlRewritingNet.UrlRewriter"/>
Line 90:   <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
          System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Line 91: </httpModules>

This is because a module was defined in the parent site which doesn’t exist in the child, but because it’s inheriting it still tries to load it.  We would also get errors complaining that modules have already been defined.

I tried initially, manually adding <remove name=”blah” /> to the child web.config to remove the entries in the child web.config it thought were defined twice, but after putting in about 10 of these and it still not working it started to get a bit ridiculous!

The trick, we found on google (How to disable web.config Inheritance for Child Applications in Subfolders in ASP.NET?) is to stop the web.config from inheriting in the top level web.config;

<location path=. inheritInChildApplications=false>

<system.web>

</system.web>
<
/location>

This stops anything being migrated down to the children, allowing you to have your full web.config in the child site, unaffected by the parent! — Make sure you don’t put this around anything else though; just the system.web section!

, ,

No Comments