<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FatLemon &#187; ASP.Net</title>
	<atom:link href="http://www.fatlemon.co.uk/tag/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fatlemon.co.uk</link>
	<description>Contemplations on software development and human factors, by Andrew Freemantle</description>
	<lastBuildDate>Sun, 29 Jan 2012 13:45:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Securing ASP.Net Web Services with Forms Authentication</title>
		<link>http://www.fatlemon.co.uk/2010/04/securing-asp-net-web-services-with-forms-authentication/</link>
		<comments>http://www.fatlemon.co.uk/2010/04/securing-asp-net-web-services-with-forms-authentication/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 07:00:33 +0000</pubDate>
		<dc:creator>Andrew Freemantle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.fatlemon.co.uk/?p=44</guid>
		<description><![CDATA[My first article for Dot Net Slackers on Securing ASP.Net Web Services with Forms Authentication is up! Have a read and let me know what you think &#8211; any feedback about the content, the writing style, the amount of code, or anything else (!) is greatly appreciated ]]></description>
			<content:encoded><![CDATA[<p>My first article for <a title="Securing ASP.Net Web Services with Forms Authentication" href="http://dotnetslackers.com/articles/aspnet/Securing-ASP-Net-Web-Services-with-Forms-Authentication.aspx" target="_blank">Dot Net Slackers on Securing ASP.Net Web Services with Forms Authentication</a> is up!</p>
<p>Have a read and let me know what you think &#8211; any feedback about the content, the writing style, the amount of code, or anything else (!) is greatly appreciated  <img src='http://www.fatlemon.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fatlemon.co.uk/2010/04/securing-asp-net-web-services-with-forms-authentication/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Automatic SVN Revision Numbering in ASP.Net MVC</title>
		<link>http://www.fatlemon.co.uk/2008/12/automatic-svn-revision-numbering-in-aspnet-mvc/</link>
		<comments>http://www.fatlemon.co.uk/2008/12/automatic-svn-revision-numbering-in-aspnet-mvc/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 15:00:30 +0000</pubDate>
		<dc:creator>Andrew Freemantle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[SubVersion]]></category>

		<guid isPermaLink="false">http://www.fatlemon.co.uk/?p=20</guid>
		<description><![CDATA[Update: I&#8217;ve written an open source .Net build tool that can also put the highest SVN revision into a file automatically on build &#8211; check it out! While working on an internal ASP.Net MVC project at work, I wondered if it was possible to get the SubVersion (SVN) repository number to be automatically updated on [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> I&#8217;ve written an <a title="WTV: Automatic date-based version numbering for .Net with WhenTheVersion" href="http://www.fatlemon.co.uk/2011/11/wtv-automatic-date-based-version-numbering-for-net-with-whentheversion/">open source .Net build tool that can also put the highest SVN revision into a file automatically on build</a> &#8211; check it out!</p>
<hr />
<p>While working on an internal <a title="ASP.Net MVC Homepage" href="http://www.asp.net/mvc" target="_self">ASP.Net MVC</a> project at work, I wondered if it was possible to get the SubVersion (SVN) repository number to be automatically updated on the webpages I was creating every time I did a build or check-in.</p>
<p>The footer at the bottom of the <a title="StackOverflow" href="http://www.stackoverflow.com" target="_self">StackOverflow.com</a> site is what we&#8217;re trying to do here (though I suspect after listening to <a title="StackOverflow Podcast 17" href="https://stackoverflow.fogbugz.com/default.asp?W24212" target="_self">their podcasts</a> that they&#8217;ve got theirs updated using custom build tasks in <a title="Cruise Control.Net" href="http://confluence.public.thoughtworks.org/display/CCNET" target="_self">CruiseControl.Net</a>)..</p>
<p><img src="/images/svn-stackoverflow.png" alt="StackOverflow.com - SVN revision" /></p>
<p>After a couple of hours of investigation, trial and error, here&#8217;s one way to do it.</p>
<p>Before we begin, we&#8217;ll need <a title="Tortoise SVN Client" href="http://tortoisesvn.tigris.org/">TortoiseSVN</a> installed, and a local working copy of your ASP.Net MVC project checked out.</p>
<p>There are essentially 3 steps..</p>
<h3>1. Create a <a title="Html Helpers 'How Do I' video - ASP.Net MVC Website" href="http://www.asp.net/learn/mvc-videos/video-402.aspx" target="_self">Html Helper</a></h3>
<p>This greatly simplifies the return of the SVN number as a string which is then trivial to place in our View Page or footer.</p>
<p>Create the following file:</p>
<pre>
Imports System.Runtime.CompilerServices

Public Module HtmlHelpers

    &lt;extension()&gt; _
    Public Function SVNRevision(ByVal helper As HtmlHelper) As String
        Dim svnFile As IO.StreamReader
        Dim svnRev As String = String.Empty
        Try
            svnFile = New IO.StreamReader(&quot;svn_rev.txt&quot;)
            svnRev = svnFile.ReadLine()
            svnRev = svnRev.Replace(&quot;&quot;&quot;&quot;, &quot;&quot;)
            svnFile.Close()
        Catch FnFex As IO.FileNotFoundException
            &#039;swallow, but write out the file and location we tried to read..
            Trace.WriteLine(&quot;HtmlHelper.SVNRevision: Ex: [&quot; &amp; FnFex.Message &amp; &quot;]&quot;)
        Finally
            If svnRev.Length = 0 Then svnRev = &quot;-&quot;
        End Try

        Return svnRev
    End Function
End Module
</pre>
<h3>2. Create a Batch File and add it as a custom build task to the project</h3>
<p>Next we create a Batch File (.bat) in the root of our project, which will call the TortoiseSVN command to retrieve the SVN revision number from our working copy.<br />
We&#8217;ll call it &#8220;CreateSvnRevFile.bat&#8221;.  Here&#8217;s the contents:</p>
<pre>
@echo off
rem # CreateSvnRevFile.bat
rem # Check the Working Copy folder is passed in..
if /I [%1%]==[] goto usage else goto start
:start
rem # (Re)Create the base file so SubWCRev has something to replace
echo "$WCREV$" &gt; svn_rev.txt
rem # Ask SubWCRev to replace with the latest revision
rem #  from the current (working copy) directory
C:\Progra~1\TortoiseSVN\bin\SubWCRev.exe %1 svn_rev.txt svn_rev.txt
rem # Copy the file for local hosting and testing purposes..
copy svn_rev.txt "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE" /Y
del svn_rev.txt /Q
goto end

:usage
echo Usage: %0 SvnWorkingCopyDir

:end
rem exit 0
</pre>
<p>Then we need to add a custom Build Event action to call the Batch File. (The Build Events dialog is in &#8220;My Project &gt; Compile &gt; Build Events&#8221;)</p>
<p><img src="/images/svn-buildevents.png" alt="My Project - Compile - Build Events" /></p>
<p>As shown above, we need to add the line to the &#8220;Post-build event command line:&#8221; box..</p>
<pre>
call "$(ProjectDir)CreateSvnRevFile.bat" "$(SolutionDir)\"
</pre>
<h3>3. Add the SVN revision number to our Page</h3>
<p>With all of that background plumbing in place, all we need to do now is add a couple of lines of code in the appropriate .aspx file wherever we want our SVN revision number to appear:</p>
<pre>
  ...
  &lt;%@ import Namespace=&quot;MyMvcProject&quot; %&gt;
  ...
  &lt;%=Html.SVNRevision()%&gt;
  ...
</pre>
<p>the first line imports our Project Namespace (which will obviously depend on your project &#8211; you may need to rebuild at this point before the =Html. autocomplete picks up the &#8216;SVNRevision()&#8217; HtmlHelper).</p>
<p>And we&#8217;re done:</p>
<p><img src="/images/svn-opsweb.png" alt="" /></p>
<h4>So, how does it work?</h4>
<p>The Post-build task CreateSvnRevFile.bat does most of the work by creating a temporary text file called svn_rev.txt containing the string &#8220;$WCREV$&#8221;, and then calls the TortoiseSVN command SubWCRev.exe on the text file to replace the string with the working copy revision number.  It&#8217;s worth noting that the revision number is held in the working copy .svn folder so this method doesn&#8217;t require a call to your SVN server to work.</p>
<p>The Html Helper code then simply tries to read the updated text file and returns the contents as a string, or it returns a dash (&#8220;-&#8221;) if there was a problem.</p>
<p>Obviously, if we&#8217;re using this on a high-traffic website or frequently referenced page then we&#8217;d want to cache the string rather than reading it from the file every time. We could do this by modifying the Html Helper to read the file once into a variable, which we could do by wrapping the actual file reading up in a singleton object, for example.</p>
<p>I hope you find it useful  <img src='http://www.fatlemon.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fatlemon.co.uk/2008/12/automatic-svn-revision-numbering-in-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

