Pinging Technorati
17 November 2008 Tips
Bubble
Copy and paste the code below into your App_Code folder. To do this  right click App_Code choose Add New Item > Class  choose vb as the language and name the class PingTechnorati or something similar.
Next set the blog URL to your own blog address and the blogName to the information entered into the <title> tag in the <head> section of your blog HTML or  if you're generating the title dynamically Page.Title in the Page_Load event of your default page.
 
Imports Microsoft.VisualBasic
Imports System.Net
Imports System.Xml
Imports system.IO
 
Public Class PingTechnorati
   Public Shared Sub PingSites()
 
    Dim pingURL As String = "http://rpc.technorati.com/rpc/ping"
    Dim blogURL As String = "blogURL"
    Dim blogName As String = "blogName"
   
   Dim technoratiPing As HttpWebRequest = CType   (WebRequest.Create(pingURL), HttpWebRequest)
        technoratiPing.Method = "POST"
        technoratiPing.ContentType = "text/xml"
        Dim streamPingRequest As Stream = CType(technoratiPing.GetRequestStream, Stream)
        Dim xmlPing As XmlTextWriter = New XmlTextWriter(streamPingRequest, System.Text.Encoding.UTF8)
        xmlPing.WriteStartDocument()
        xmlPing.WriteStartElement("methodCall")
        xmlPing.WriteElementString("methodName", "weblogUpdates.ping")
        xmlPing.WriteStartElement("params")
        xmlPing.WriteStartElement("param")
        xmlPing.WriteElementString("value", "blogName")
        xmlPing.WriteEndElement()
        xmlPing.WriteStartElement("param")
        xmlPing.WriteElementString("value", "blogURL")
        xmlPing.WriteEndElement()
        xmlPing.WriteEndElement()
        xmlPing.WriteEndElement()
        xmlPing.Close()
 
  Dim technoratiPingResponse As HttpWebResponse = CType(technoratiPing.GetResponse, HttpWebResponse)
        Dim streamPingResponse As StreamReader = New StreamReader(technoratiPingResponse.GetResponseStream)
        Dim strResult As String = streamPingResponse.ReadToEnd
        streamPingResponse.Close()
        technoratiPingResponse.Close()
      
    End Sub
End Class
 
Next simply call the method in your submit event for blog enteries.
 
Protected Sub btnPost_Click(ByVal sender As Object, ByVal  e As e System.EventArgs) Handles bntPost.Click
 
      PingTechnorati.PingSites()
 
So now every time you post an article to your blog Technorati is automatically pinged.
 
 
Flash in valid xhtml
15 November 2008 Tips
Bubble
Using the <embed> element in your markup will cause validation to fail. Instead use the <object> element.
 
<object
type="application/x-shockwave-flash"
data="movie.swf"
width="425" height="344">
<param name="movie" value="movie.swf" />
</object>
 
 
Url Rewriters
12 November 2008 Tips
Bubble
If like me you decide to use Friendly URLs you will at some point need to download and inplement a URL Rewriter.
 
For example say you have a blog article called Url Rewriter,  passing title as the parameter in the querystring the url would be
 
http://www.yoursite.com/article.aspx?Title= Url%20Rewriter.
 
Converting this 'dirty' url to the more friendly
 
http://www.yoursite.com/article/url-rewriter.aspx
 
will result in problems when trying to locate the article in the database. The title field actually holds Url Rewriter and not url-rewriter and therfore the article will not be found.
 
The open source URL Rewriter is avalilable for download from
 
 
Simply download the source files and follow the online instructions. In all probability you will need to create and register a Custom Transform.
 
To create a custom transform class to transform hyphens back to spaces right click App_Code > Add New Item > Class. Name the class something like HyphenToSpace and choose vb as the language. Copy and paste the code below:
 
Imports Microsoft.VisualBasic
Imports System
Imports System.Web
Imports Intelligencia.UrlRewriter.Utilities

Namespace Intelligencia.UrlRewriter
 
    Public Class HyphenToSpace
        Implements IRewriteTransform
 
        Public Function ApplyTransform(ByVal input As String) As String Implements Intelligencia.UrlRewriter.IRewriteTransform.ApplyTransform  
          
            Return input.Replace("-", " ")
        End Function
 
        Public ReadOnly Property Name() As String Implements Intelligencia.UrlRewriter.IRewriteTransform.Name 
            Get
 
                Return "transform"
 
            End Get
 
        End Property
 
    End Class

End Namespace
 
To register the transform copy and paste the code below to your web.config file:
 
<rewriter>    
<registertransform= "Intelligencia.UrlRewriter.HyphenToSpace,App_Code" />
</rewriter>
 
Then set the rule:
 
<rewrite url="~Article/(.+).aspx" to "~/Article.aspx?Title=${transform($1)}" />
 
Note that the tilde (~) only works with sever controls
Implementing Friendly URLs
11 November 2008 Tips
Bubble
I recently decided to implement Friendly URLs on my site in a bid to follow recent trends. What I wanted was to remove  character spaces denoted by  %20 and replace them with hyphens (-). Using Server.UrlEncode simply changes the character spaces appearing in the web browser address bar to a positive sign (+).
 
Dynamic URL
http://macocz-design.com/Post.aspx?title=Impementing%20Friendly%20URLs
 
Server.UrlEncode method
http://macocz-design.com/Post.aspx?Title=Implementing+Friendly+URLs
 
Friendly URL
http://macocz-design.com/post.aspx?title=implementing-friendly-urls
 
Right click the App_Code folder > Add New Item>Class.vb
Choose appropriate name like FriendlyUrl and the language VB.
Copy and paste the following code:
 
Public Class FriendlyUrl
 
Public Shared Function GenerateUrl(ByVal strTitle As String) As String
 
strTitle = strTitle.Trim()
strTitle = strTitle.Trim("-"c)
strTitle = strTitle.ToLower()
 
Dim chars As Char() = "$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray()
 
strTitle = strTitle.Replace("c#", "C-Sharp")
strTitle = strTitle.Replace("vb.net", "VB-Net")
strTitle = strTitle.Replace("asp.net", "Asp-Net")
strTitle = strTitle.Replace(".", "-")
For i As Integer = 0 To chars.Length - 1
Dim strChar As String = chars.GetValue(i).ToString()
If strTitle.Contains(strChar) Then
strTitle = strTitle.Replace(strChar, String.Empty)
End If
Next
strTitle = strTitle.Replace(" ", "-")
strTitle = strTitle.Trim()
strTitle = strTitle.Trim("-"c)
Return strTitle
 
End Function
 
End Class
 
Call the Function:
 
<%#FriendlyUrl.GenerateUrl(Container.DataItem("Title")) %>