<?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"
	>

<channel>
	<title>JoshSalwen.com</title>
	<atom:link href="http://www.joshsalwen.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joshsalwen.com</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Fri, 03 Oct 2008 20:20:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Must See - Warren Buffett Interview</title>
		<link>http://www.joshsalwen.com/index.php/must-see-warren-buffett-interview/</link>
		<comments>http://www.joshsalwen.com/index.php/must-see-warren-buffett-interview/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 20:03:40 +0000</pubDate>
		<dc:creator>jsalwen</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[economy]]></category>

		<guid isPermaLink="false">http://www.joshsalwen.com/?p=11</guid>
		<description><![CDATA[I highly recommend watching (or at least listening to) the Warren Buffett interview with Charlie Rose.
]]></description>
			<content:encoded><![CDATA[<p>I highly recommend watching (or at least listening to) the <a href="http://www.thirteen.org/newsandpublicaffairs/watch-warren-buffett-interview-online">Warren Buffett interview with Charlie Rose</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joshsalwen.com/index.php/must-see-warren-buffett-interview/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WordPress Adoption &#8212; Confessions of an ASP.NET Developer</title>
		<link>http://www.joshsalwen.com/index.php/wordpress-adoption-confessions-of-an-aspnet-developer/</link>
		<comments>http://www.joshsalwen.com/index.php/wordpress-adoption-confessions-of-an-aspnet-developer/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 18:43:07 +0000</pubDate>
		<dc:creator>jsalwen</dc:creator>
		
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.joshsalwen.com/?p=4</guid>
		<description><![CDATA[A bit about me:

I am web developer
I am a .NET developer (ASP.NET, C#, VB)
I am a Web Standards freak

OK, those last two don&#8217;t go very well together, and that has been my cross to bear. 
For years, I have been looking for an open source ASP.NET CMS/blogging engine that I could use for myself and [...]]]></description>
			<content:encoded><![CDATA[<p>A bit about me:</p>
<ul>
<li>I am web developer</li>
<li>I am a .NET developer (ASP.NET, C#, VB)</li>
<li>I am a <a href="http://en.wikipedia.org/wiki/Web_standards">Web Standards</a> freak</li>
</ul>
<p>OK, those last two don&#8217;t go very well together, and that has been my cross to bear. </p>
<p>For years, I have been looking for an open source ASP.NET CMS/blogging engine that I could use for myself and for other small websites. The catch was it had to adhere to Web Standards (valid XHTML 1.0 Strict markup, CSS for layout, etc). I found a few that sort of worked and I even wrote a few custom ones myself, but I was never satisfied.</p>
<p>Well, I give up.</p>
<p>For the last few months, I have been working on the website for my son&#8217;s (now former &#8212; he started kindergarten on Wednesday) preschool. As usual, I had no problem getting the site working using ASP.NET (everything validated, cleanish CSS), BUT I hadn&#8217;t tackled how I was going to handle the CMS.</p>
<p>I started down the road of using the MVC pattern in ASP.NET 3.5 with the help of <a href="http://www.tavaresstudios.com">Chris Tavares&#8217;</a> article, <a href="http://msdn.microsoft.com/en-us/magazine/cc337884.aspx">Building Web Apps without Web Forms</a>. But then &#8230;</p>
<p>While attending <a href="http://www.gotomedia.com/company_team.html">Kelly Goto&#8217;s</a> presentation at (the best conference I&#8217;ve yet attended) <a href="http://www.aneventapart.com/events/2008/sanfrancisco/">An Event Apart in San Francisco</a>, she made an offhand comment about creating a website for her mom. She talked about simply getting <a href="http://wordpress.org/">WordPress</a> up and running for her mom in about 15 minutes, and letting her mom take over. Preso &#8230; a website.</p>
<p>Now, I don&#8217;t know much about WordPress or PHP or MySql, but if Kelly&#8217;s mom can do it &#8230;</p>
<p>I then spent the next few evening doing some pilot projects to see how easy or hard it would be to get WordPress to act more like a CMS, and I&#8217;m converted. So far I haven&#8217;t found any gotchas that will prevent me from using WordPress for smaller websites. And even giving my handicap of not knowing PHP, it has been easier to write themes for WordPress than it would have been to write my own CMS in ASP.NET.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joshsalwen.com/index.php/wordpress-adoption-confessions-of-an-aspnet-developer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Programmatically Adding Meta Tags to ASP.NET 2.0 Pages</title>
		<link>http://www.joshsalwen.com/index.php/programmatically-adding-meta-tags-to-aspnet-20-pages/</link>
		<comments>http://www.joshsalwen.com/index.php/programmatically-adding-meta-tags-to-aspnet-20-pages/#comments</comments>
		<pubDate>Sat, 10 Dec 2005 22:41:51 +0000</pubDate>
		<dc:creator>jsalwen</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.joshsalwen.com/?p=6</guid>
		<description><![CDATA[The Problem
I was recently looking for a way to programmatically add and update Meta Tags in ASP.NET 2.0. This is a fairly simple thing to do with standard .aspx pages. Just add ID and Runat attributes to the Head element and reference the control in the code behind. However, this is not so simple when [...]]]></description>
			<content:encoded><![CDATA[<h2>The Problem</h2>
<p>I was recently looking for a way to programmatically add and update Meta Tags in ASP.NET 2.0. This is a fairly simple thing to do with standard .aspx pages. Just add <code>ID</code> and <code>Runat</code> attributes to the Head element and reference the control in the code behind. However, this is not so simple when working with MasterPages, which I am. What I wanted was a way to:</p>
<ul>
<li>Add a new Meta tag</li>
<li>Change the <code>content</code> attribute of an existing Meta Tag</li>
<li>Append data into the <code>content</code> attribute of an existing Meta Tag</li>
<li>Do any of the above from a MasterPage, Page or User Control</li>
</ul>
<h2>AddMetaTag Utility in <code>App_Code</code></h2>
<p>Initially, in my Master Pages I added a AddMetaTag method, which the Content Pages could call. However, this did not allow me to call the method from User Controls. It was also a maintenance pain, since the code had to be added to each Master Page.</p>
<p>A simple solution was to take advantage of the App_Code folder and add a Utility Class, which could be called from anywhere in the Web project. The <code>AddMetaTag</code> method needs three parameters passed, the <code>Page</code> reference and strings for the <code>Name</code> and <code>Content</code> attributes of the Meta Tag.</p>
<h3>C#</h3>
<h4><code>Utilities.cs</code> (in <code>App_Code</code>)</h4>
<pre>
<code>
public class Utilities {
  public static void AddMetaTag(Page thisPage, string name, string content) {
    ...
  }
}
</code>
</pre>
<h4><code>Default.aspx.cs</code></h4>
<pre>
<code>
protected void Page_Load(object sender, EventArgs e) {
  Utilities.AddMetaTag(this.Page, "author", "Josh Salwen");
}
</code>
</pre>
<h3>VB</h3>
<h4><code>Utilities.vb</code> (in <code>App_Code</code>)</h4>
<pre>
<code>
Public Class Utilities
  Public Shared Sub AddMetaTag(ByVal thisPage As Page, ByVal name As String, ByVal content As String)
    ...
  End Sub
End Class
</code>
</pre>
<h4><code>Default.aspx.vb</code></h4>
<pre>
<code>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  Utilities.AddMetaTag(Me.Page, "author", "Josh Salwen")
End Sub
</code>
</pre>
<h2>Adding a New Meta Tag</h2>
<p>Using the <code><a  href="http://msdn2.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlmeta.aspx">System.Web.UI.HtmlControls.HtmlMeta</a></code> class makes it easy to create a Meta Tag.</p>
<h3>C#</h3>
<pre>
<code class="cs">
HtmlMeta meta = new HtmlMeta();
meta.Name = "Author";
meta.Content = "Josh Salwen";
</code>
</pre>
<h3>VB</h3>
<pre>
<code class="vb">
Dim meta As New HtmlMeta
meta.Name = "Author"
meta.Content = "Josh Salwen"
</code>
</pre>
<p>The trick is adding it into the HTML <code>Head</code> element.</p>
<p>By default, Visual Studio 2005 adds a <code>runat="server"</code> to the <code>Head</code> element in both <code>.master</code> pages and <code>.aspx</code> pages (if it is not a content page which references a Master Page). As long as the <code>runat="server"</code> is not removed, the <code><a  href="http://msdn2.microsoft.com/en-us/library/system.web.ui.page.header.aspx">Page.Header</a></code> property can be accessed. If it is removed, then it is not possible to access the <code>Page.Header</code>, so when referencing the <code>Header</code> is is important to make sure it is not <code class="cs">null</code> (or <code class="vb">Nothing</code>).</p>
<p>Once the <code>Page.Header</code> is referenced, then you create a new <code>HtmlMeta</code> object and add it to the <code>Page.Header</code> Controls.</p>
<h3>C#</h3>
<pre>
<code class="cs">
public static void AddMetaTag(Page thisPage, String name, String content) {
  HtmlHead header = (HtmlHead)thisPage.Header;
  if (header != null) {
    HtmlMeta meta = new HtmlMeta();
    meta.Name = name;
    meta.Content = content;
    header.Controls.Add(meta);
  }
}
</code>
</pre>
<h3>VB</h3>
<pre>
<code class="vb">
Public Shared Sub AddMetaTag(ByVal thisPage As Page, ByVal name As String, ByVal content As String)
  Dim header As HtmlHead = DirectCast(thisPage.Header, HtmlHead)
  If Not IsNothing(header) Then
    Dim meta As New HtmlMeta
    meta.Name = name
    meta.Content = content
    header.Controls.Add(meta)
  End If
End Sub
</code>
</pre>
<h2>Updating an Existing Meta Tag</h2>
<p>Once the functionality was in place to add a Meta Tag, I just needed to add the ability to update an existing tag. In order to do this, the method does the following:</p>
<ul>
<li>Loops through the <code>Controls</code> in the Header</li>
<li>Checks if the <code>Control</code> is an <code>HtmlMeta</code></li>
<li>Checks if the <code>Name</code> attributes are the same</li>
<li>Updates the <code>Content</code> attribute and exits the method</li>
</ul>
<h3>C#</h3>
<pre>
<code class="cs">
public static void AddMetaTag(Page thisPage, String name, String content) {
  HtmlHead header = (HtmlHead)thisPage.Header;
  if (header != null) {
    HtmlMeta meta = new HtmlMeta();
    // Loop through all the controls in the Header
    foreach (Control ctrl in header.Controls) {
      // Check if the control is a Meta Tag
      if (ctrl is HtmlMeta) {
        // Get the Meta Tag and check if the name is the same
        meta = (HtmlMeta)ctrl;
        if (name.Equals(meta.Name, StringComparison.InvariantCultureIgnoreCase)) {
          // Since the Meta Tag already exists, simply update and exit
          meta.Content = content;
          return;
        }
      }
    }
    meta = new HtmlMeta();
    meta.Name = name;
    meta.Content = content;
    header.Controls.Add(meta);
  }
}
</code>
</pre>
<h3>VB</h3>
<pre>
<code>
Public Shared Sub AddMetaTag(ByVal thisPage As Page, ByVal name As String, ByVal content As String)
  Dim header As HtmlHead = DirectCast(thisPage.Header, HtmlHead)
  If Not IsNothing(header) Then
    Dim meta As New HtmlMeta

    ' Loop through all the controls in the Header
    For Each ctrl as Control in header.Controls
      ' Check if the control is a Meta Tag
      If TypeOf ctrl Is HtmlMeta Then
        ' Get the Meta Tag and check if the name is the same
        meta = DirectCast(ctrl, HtmlMeta)
        If name.Equals(meta.Name, StringComparison.InvariantCultureIgnoreCase) Then
          ' Since the Meta Tag already exists, simply update and exit
          meta.Content = content
          Return
        End If
      End If
    Next
    meta = New HtmlMeta
    meta.Name = name
    meta.Content = content
    header.Controls.Add(meta)
  End If
End Sub
</code>
</pre>
<h2>&#8230; And a Few More Things</h2>
<p>I noted above that I want to be able to append data as well. I also want to compare the <code>Name</code> and <code>Lang</code> attributes, since you can add the same Meta Tag for different languages. I have included this code in the source code, if you want to check it out.</p>
<p>And finally, in the ASP.NET 2.0 Alpha, the <code>Header</code> had <code>MetaData.Add</code> (I think that is what it was called), so Microsoft was thinking about this at one point. I&#8217;m not sure what happened.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joshsalwen.com/index.php/programmatically-adding-meta-tags-to-aspnet-20-pages/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
