About The Author
Michael Flynn is a Web Developer at Terralever, an interactive marketing agency based in Tempe, AZ. He specializes in web technologies that include C# .NET, SQL, XML, AJAX, jQuery, Flash, and also skills in Photoshop and Illustrator. He was been involved in web development since 1998, and earned a Bachelors and Masters degree in Computer Engineering and Computer Science from the Univerisity of Louisville and holds an MSCT certificate in Web Applications.
Calendar
<<  September 2010  >>
SMTWTFS
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Microformats .NET Toolkit - hCard, hCalendar and XFN

I recently got fascinated by Microformats.  Not sure why but its a neat concept that is catching on as Microsoft and Google are taking notice.  I recently wanted to create an easy way to render the most common Microformats, the hCard and hCalendar.  There are so many properties that one can assign it would be very hard to remember what goes where, misspelling, or even an existing property you didn't know existed.  Microformats are adding additions all the time so this would be perfect for someone who didn't want to memorize and check the Microformats website periodically for them. Below is the rendering of three controls I created for this toolkit.

 

hCalendar

Terralever Office Upgrade Bash!
5/7/2009
Tempe Arizona
http://www.terralever.com
Come check out Terralever's new digs and help us celebrate our growth as we officially unveil our new location!

hCard

N 48° 81.6667 E 2° 36.6667
home: 555-555-5555
work: 444-444-4444
Microsoft Outlook
Terralever
dom
425 S. Mill Avenue
Suite 201
Tempe AZ 85281
US

XFN

Terralever

 The control structure is also below.  I have seen some controls developers had made, and they do the job but they are not scalable.  I wanted to create a control that was scalable, and shared common properties. Below is the hCalendar, hCard, and XFN control.  You can read about all these on the Microformats website.

hCalendar

<mf:hCalendar runat="server" ID="hCalendar">
        <Properties>
            <mf:Summary Value="Terralever Office Upgrade Bash!" />
            <mf:DateCollection>
                <Dates>
                    <mf:StartDate DateTime="5/7/2009" />
                </Dates>
            </mf:DateCollection>
            <mf:Location Value="Tempe Arizona" />
            <mf:Url Value="http://www.terralever.com" />
            <mf:Description Value="Come check out Terralever's new digs and help us celebrate our growth as we officially unveil our new location!" />
        </Properties>
    </mf:hCalendar>

hCard

 <mf:hCard ID="hCard" runat="server">
        <Properties>
            <mf:CardGeo>
                <Coordinates>
                    <mf:Latitude Text="N 48° 81.6667" Value="48.816667" />
                    <mf:Longitude Text="E 2° 36.6667" Value="2.366667" />
                </Coordinates>
            </mf:CardGeo>
            <mf:NameCollection>
                <Names>
                    <mf:Name PreferredName="true" Url="http://www.terralever.com" HtmlTag="Div">
                        <NamePropertyCollection>
                            <mf:NameProperty Type="HonorificPrefix" Value="Mr." />
                            <mf:NameProperty Type="GivenName" Value="Michael" />
                            <mf:NameProperty Type="AdditionalName" Value="Saul" />
                            <mf:NameProperty Type="FamilyName" Value="Flynn" SortString="true" />
                            <mf:NameProperty Type="HonorificSuffix" Value="Jr." />
                        </NamePropertyCollection>
                    </mf:Name>
                </Names>
            </mf:NameCollection>
            <mf:TeleCommunicationCollection>
                <TeleCommunications>
                    <mf:Telephone Type="Home" Value="555-555-5555" Preferred="true" />
                    <mf:Telephone Type="Work" Value="444-444-4444" />
                    <mf:Email Type="Internet" Value="mikef@terralever.com" Preferred="true" />
                    <mf:Mailer Value="Microsoft Outlook" />
                </TeleCommunications>
            </mf:TeleCommunicationCollection>
            <mf:CompanyCollection List="true">
                <Companies>
                    <mf:Company PreferredName="false" Name="Terralever" HtmlTag="Div" Url="http://www.terralever.com">
                        <AddressCollection>
                            <Addresses>
                                <mf:Address Type="Domestic" StateCode="true" CountryCode="true">
                                    <AddressContainerCollection>
                                        <mf:AddressContainer>
                                            <AddressPropertyCollection>
                                                <mf:AddressProperty Type="StreetAddress" Value="425 S. Mill Avenue" HtmlTag="Div" />
                                                <mf:AddressProperty Type="ExtendedAddress" Value="Suite 201" HtmlTag="Div" />
                                            </AddressPropertyCollection>
                                        </mf:AddressContainer>
                                        <mf:AddressContainer HtmlTag="Div">
                                            <AddressPropertyCollection>
                                                <mf:AddressProperty Type="Locality" Value="Tempe" HtmlTag="Span" />
                                                <mf:AddressProperty Type="Region" Value="Arizona" HtmlTag="Span" />
                                                <mf:AddressProperty Type="PostalCode" Value="85281" HtmlTag="Span" />
                                            </AddressPropertyCollection>
                                        </mf:AddressContainer>
                                        <mf:AddressContainer>
                                            <AddressPropertyCollection>
                                                <mf:AddressProperty Type="CountryName" Value="United States" HtmlTag="Div" />
                                            </AddressPropertyCollection>
                                        </mf:AddressContainer>
                                    </AddressContainerCollection>
                                </mf:Address>
                            </Addresses>
                        </AddressCollection>
                    </mf:Company>
                </Companies>
            </mf:CompanyCollection>
            <mf:MessagingCollection>
                <Messaging>
                    <mf:IMPP Type="AIM" InstantMessageName="cblaze22@gmail.com" />
                    <mf:IMPP Type="MSN" InstantMessageName="mikef@terralever.com" />
                </Messaging>
            </mf:MessagingCollection>
        </Propert

XFN

<mf:XFNLink ID="xfn" runat="server" Text="Terralever" NavigateUrl="http://www.terralever.com">
        <XFN Family="Parent"></XFN>
    </mf:XFNLink>

 

You can download the toolkit below

Microformats.NET.zip (157.63 kb)

Posted on 7/13/2009 4:28:00 PM by cblaze22

Permalink | Comments (4) | Post RSSRSS comment feed |

Categories: ASP.NET | Server Controls | Microformats

Tags:

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Use a WCF Service with HTTP and HTTPS in C#

I had a problem with a WCF service that was having problems on a secure page using SSL.  The error said the endpoint could not be found.  I found some resources on making a service HTTPS ready, but not for both.  I finally figured it out that I need two endpoints pointing to the same service.  One endpoing contained another property called "bindingConfiguration" that maps a binding that has a mode of transport which enables an endpoint for https.  The bolded text below is what you need to enable a service for HTTPS.

   

<system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

    <behaviors>

        <endpointBehaviors>

            <behavior name="WebServicesBehavior">

                <webHttp/>

            </behavior>

        </endpointBehaviors>

    </behaviors>

    <services>

        <service name="WebService">

            <endpoint binding="webHttpBinding" contract="IWebService" behaviorConfiguration="WebServicesBehavior"/>

            <endpoint binding="webHttpBinding" bindingConfiguration="webBinding" contract="IWebService" behaviorConfiguration="WebServicesBehavior"/>

        </service>

    </services>

    <bindings>

        <webHttpBinding>

            <binding name="webBinding">

                <security mode="Transport">

                    <transport clientCredentialType="None"/>

                </security>

            </binding>

        </webHttpBinding>

    </bindings>

</system.serviceModel>

Posted on 10/18/2008 12:54:00 AM by cblaze22

Permalink | Comments (3) | Post RSSRSS comment feed |

Categories: ASP.NET | Development Tips | Tips | WCF

Tags: ,

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Http To Https And Back with a Basepage in ASP.NET C#

I needed to have one page redirect to a https protocol, and when leaving that page go back to the http protocol.  I wanted a easy way that would be handled in one place, but have the ability to be overridden when necessary.  I always create a basepage for all my pages, so I decided to create a method that a page can override.  I have a page called checkout.aspx that needs to have https, so I override the parent class to redirect it to the https page.  If the user leaves the page, they will then be redirected back to http with the basepage implementation.

Basepage.cs

public virtual void SetProtocol()

{

    if (Request.ServerVariables["HTTPS"].ToString().ToLower() == "on")

    {

        string url = string.Format("http://{0}{1}", HttpContext.Current.Request.Url.Authority, Request.RawUrl);

        Response.Redirect(url, true);

    }

}

 

protected override void OnInit(EventArgs e)

{

    SetProtocol();

    base.OnInit(e);

}

 

 

 

Checkout.cs

 

public override void SetProtocol()

{

    if (Request.ServerVariables["HTTPS"].ToString().ToLower() == "off")

    {

        string url = string.Format("{0}/checkout", Utility.RootUrl).Insert(4, "s");

        Response.Redirect(url, true);

    }

}

 

protected void Page_Load(object sender, EventArgs e)

{

    SetProtocol();

}

Posted on 9/25/2008 11:05:00 PM by cblaze22

Permalink | Comments (1) | Post RSSRSS comment feed |

Categories: ASP.NET | Development Tips | Tips

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Validation Summary For Multiple User Controls in C# ASP.NET

I was looking for a simple way to have the convenience of self contained controls, but still use a single validation summary.   I created a base class for user controls so code can be reused without repeating it and a property called ValidationGroup that finds all validation controls in the control and assigns the validation group to them.

public class BaseControl : UserControl
{
    public BaseControl()
    {

    }

    public virtual string ValidationGroup
    {
        set
        {
            foreach (Control control in this.Controls)
            {
                if (control is BaseValidator)
                {
                    ((BaseValidator)control).ValidationGroup = value;
                }
            }
        }
    }
}

Below is an example of a validation summary and a user control called address that finds all controls within it to use the validation group of the validation summary.

<asp:ValidationSummary CssClass="validationSummary" runat="server" ID="ValidationSummary"
    ValidationGroup="vgEvent"  /> 

 <uc:Address ID="CalendarAddress" runat="server" ValidationGroup="vgEvent" />

Posted on 9/22/2008 12:44:00 AM by cblaze22

Permalink | Comments (3) | Post RSSRSS comment feed |

Categories: ASP.NET | Development Tips | Tips | User Controls

Tags: ,

Currently rated 4.0 by 2 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Universal Root/Base Url

I have tried many ways to get the root/base url of a website.  A static approach to this is to store it in the web.config appsettings section and calling it in code.

<appSettings>
        <add key="RootUrl" value="http://www.mydotnetworld.com"/>
</appSettings>

string rootUrl = ConfigurationManager.AppSettings["RootUrl"];

This isnt convenient when you are working locally and the port number might change.  Another way is to call a method to get the base/root of the website.  I have seen numerous ways to do this and most of them had flaws.  I created my own that I use in every project and hasnt failed me yet.  It works in any development environment.

public static string RootUrl
{
    get
    {
        HttpContext context = HttpContext.Current;
        string executionPath = context.Request.ApplicationPath;
        return string.Format("{0}://{1}{2}", context.Request.Url.Scheme,
                                                                context.Request.Url.Authority,
                                                                executionPath.Length == 1 ? string.Empty : executionPath);
    }
}

I place this function inside a utility class and call it wherever the base/url is needed.  It also comes in handy within javascript.

var rooUrl = <%= Utility.RootUrl %>;

Posted on 8/16/2008 2:14:00 AM by cblaze22

Permalink | Comments (1) | Post RSSRSS comment feed |

Categories: ASP.NET | Development Tips

Tags:

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5