February 2004 - Posts

Upcoming Talk on WS-Security
29 February 04 11:34 AM | Scott Mitchell

Microsoft's DevDays is coming to San Diego on March 2nd, down at the San Diego Convention Center. Afterwards, I'll be speaking at the San Diego .NET Developers Group, giving a talk on WS-Security, one of the (many) Web Service Enhancement (WSE) standards. My talk is the opener for Brent Rector's two hour preview of Longhorn. My talk, specifically, gives a brief overview of WS-Security and then looks at implementing UsernameToken authentication and asymmetric encryption using X.509 certificates. Hope to see you there!

For those unable to attend, you can download the PowerPoint slides and code demos here.

Filed under:
skmMenu 2.2 Released
22 February 04 02:49 PM | Scott Mitchell

Over the weekend I released the latest version of skmMenu, Version 2.2. (skmMenu is a free, open-source custom ASP.NET control that displays client-side menus.) skmMenu 2.2 fixed a couple of bugs, and added a number of new features. The coolest feature to be added, in my opinion, is the concept of roles. There are many cases where the menu items to display depend on the current user viewing the Web page. For example, if the logged in user is an administrator, they may be able to see more menu options than a non-authenticated user, or a user with less access. Previous to version 2.2, to accomodate such functionality you'd have to programmatically build up the menu based on the current user's access rights. So, those who needed the menu generated based on a user's rights were unable to use the simpler approach of just binding the menu to an appropriately structured XML file.

With Version 2.2, a developer can now assign any number of roles to any menu item in the XML markup. For example, imagine you wanted a menu item that was only visible to admins and managers. You could use XML like:

<menu>
<menuItem>
<text>Only Accessible to Admins/Managers</text>
<roles>admin,manager</roles>
...
</menuItem>
...
</menu>

When binding the XML to skmMenu, you can specify what roles the current user belongs to. For example, say the current user belonged to admins role, you could use:

Menu1.UserRoles.Add(”admin”)
Menu1.DataSource = path to XML file
Menu1.DataBind()

And, for this user, they'd see the “Only Accessible to Admins/Managers” menu item. However, if someone wasn't in the admin or manager roles, they would not see the menu item. These menu item roles can be appplied at any level of granularity: as a top-level menu item, or a menu item in a submenu or a submenu of a submenu, and so on.

You can see a live demo illustrating the functionality of roles at http://skmmenu.com/menu/Examples/Roles.aspx.

Eventually, I'd like to have it so that skmMenu ships with a GUI tool for creating the menu item XML file - right now you have to enter it by hand, referring to the XML schema and hope you don't make a typo or mess up on the casing of the tag names...

For more information on skmMenu, or to download the complete source code, visit skmMenu.com...

Filed under:
An Extensive Examination of Data Structures, Part 4 Available
20 February 04 02:31 PM | Scott Mitchell

A mere 10 days ago An Extensive Examination of Data Structures: Part 3 was published on MSDN. Part 3 looked at trees, binary trees, and binary search trees (BSTs), and looked at implementing both binary tree and BST classes in C#.

Today, Part 4 of the article series was made available. Part 4 starts with a quick look at self-balancing BSTs, and then moves on to an in-depth examination of skip lists, which are a randomized, mutated linked list that provides log2 n asymptotic time for searches, inserts, and deletes. The article includes complete, working C# source code for the skip list class as well. And, yes, Part 4 is another testament to my long-windedness, as it clocks in at 31 printed pages. (In my defense, it's hard to be terse when talking about this topic matter; also, there are many pretty pictures and diagrams which quickly inflate the page count.)

Enjoy!

Filed under:
I'll be Giving a User Group Talk on Feb. 17th
16 February 04 12:14 PM | Scott Mitchell

If you live in Southern California, let me invite you to the February 17th San Diego ASP.NET Special Interest Group meeting. It starts at 6:30 pm, and I'll be giving a talk on consuming RSS with RssFeed and syndicating your Web site's content by creating an RSS feed. The meeting is free and meets at Microsoft's San Diego Office in UTC. Hope to see you there!

For those who can't make it, the slides I will be going over are available here.

Filed under: ,
Case Study: Match.com
13 February 04 09:30 AM | Scott Mitchell

15Seconds.com has published a short piece that examines Match.com's migration from classic ASP to ASP.NET [read the case study]. The case study is, unfortunately, rather short, and does not delve into too great of detail, but there are some good statistics from Jason Alexander, the project lead at Match.com (who also is one of the main contributors for nGallery):

  • Classic ASP: 104 servers running Windows 2000, IIS 5, and ASP 3.0 using MS SQL Server 2000.
  • ASP.NET: 78 servers running Windows 2003, IIS 6, and ASP.NET (still using MS SQL Server 2000).

The upgrade to ASP.NET, which took eight months and ~500,000 lines of code, improved performance to the point where they could drop 26 servers. Nice. Also, from the case study: the Web servers operate at about 25-35% CPU utilization and has exhibited 99.9% availability since launch.

Let's hear it for ASP.NET.

Giving .Text a Calendar View
12 February 04 09:13 PM | Scott Mitchell

Many blog engines provide a calendar view when visiting the blog via the Web. Typically the calendar shows the current month, with days that have one or more entries rendered as hyperlinks. Clicking on the link for a given day displays the posts for that day. Unfortunately .Text doesn't provide such a built-in calendar view, so I decided to create my own. (As to why .Text doesn't include a calendar view, Scott Watermasysk indicated that there were issues with the ASP.NET Calendar control and CSS. Not being a CSS expert, I'm not sure exactly what issues there are, but in my own experiment I'm happy with the rendered display of my calendar, and all stylesheets seem to be playing nicely together...)

In any event, take a minute to check out the Scott on Writing homepage - up in the upper-right hand corner you can see a calendar view. Pretty cool, eh? I'd like to share how I accomplished this.

DISCLAIMER: To add the Calendar control I decided to take a path of least resistance, and actually had the entire thing written in under ten minutes. I used a user control - a compiled control might be a better choice. There may be more efficient techniques to use than I employed. If you have suggestions on improvements, feel free to post them; if you want to use the code, feel free, but realize it was created hastily with a “let's get something working before my fiancee gets home from work”-attitude.

TECHNICAL NOTE: I am using .Text 0.94 - I have no idea if this code will work “as-is“ with different versions. I imagine it would, although if the database schema has changed, that would require a slight update of the SQL query used to get the blog entries for a given month/year....

I started by creating a User Control and adding a Calendar. My aim was to create an event handler for the Calendar's DayRender event, and then see if the particular day being rendered had any posts and, if so, display a hyperlink to the correct /archive/ URL. (To view the posts on MM/DD/YYYY, you can simply visit /archive/MMDDYYYY.aspx - ah, the power of HTTP handlers.)

Of course, I didn't want to have to hit the database once for each day in the month, so I loaded all of the blog entries from the month into a DataTable (ordered by the date of entry, in ascending order). The SQL query to run (which was moved into a stored procedure) was:

SELECT DateAdded FROM blog_Content (nolock)
WHERE PostType=1 
      AND BlogID = @BlogID
      AND DATEPART(yyyy, DateAdded) = @Year 
      AND DATEPART(m, DateAdded) = @Month
ORDER BY DateAdded

Here, @BlogID is the ID of the blog whose dates of posts you want to show (if you are hosting multiple blogs on a single .Text install, each blog has its own BlogID). @Year and @Month are the year and month of blog entries to get. (The PostType=1 gets only blog entries - not comments, tracebacks, etc.)

In my User Control I have a DataTable (named dates) scoped at the class level that is populated with the results of the above SQL query. The code that performs this follows:

private void LoadMonthData()
{
SqlConnection myConnection = new SqlConnection(connection string);

SqlCommand myCommand = new SqlCommand("blog_GetBlogEntriesForMonth", myConnection);
myCommand.CommandType = CommandType.StoredProcedure

// selDate is the currently selected date...
myCommand.Parameters.Add(new SqlParameter("@Year", selDate.Year));
myCommand.Parameters.Add(new SqlParameter("@Month", selDate.Month));

SqlParameter blogID = new SqlParameter();
blogID.Value = 0;
blogID.ParameterName = "@BlogID";
myCommand.Parameters.Add(blogID);

// Fill the dates DataTable...
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
myAdapter.Fill(dates);

myConnection.Close();

// Keep track of how many records are in the DataTable...
dateCount = dates.Rows.Count;
}

In addition to having the dates DataTable scoped at class level, I also have two additional ints: one keeps track of how many total entries there are for the month (dateCount), the other stored the index of the current record being examined in dates (this variable is named currentDate).

In the event handler for the Calendar control's DayRender event, I check to see if the current date being rendered equals the date in the current row in dates being examined. If it does, I change the TableCell's Text property to a hyperlink and update currentDate accordingly - otherwise I do nothing. The code for this event handler follows:

private void dayRender(object sender, DayRenderEventArgs e)
{
if (currentDate < dateCount &&
e.Day.Date == Convert.ToDateTime(dates.Rows[currentDate]["DateAdded"]).Date)
{
e.Cell.Text = "<A href="\" +="" ?? archive sowBlog>
String.Format("{0:d2}{1:d2}{2:d4}",
e.Day.Date.Month, e.Day.Date.Day, e.Day.Date.Year) +
".aspx\"><U>" + e.Day.Date.Day + "</U></A>";
// There might be multiple entries per day, so advance currentDate until
// we're on a different day...
do
{
currentDate++;
} while ((currentDate < dateCount &&
e.Day.Date == Convert.ToDateTime(dates.Rows[currentDate]["DateAdded"]).Date));
}
}

There are some other slight details involved, but the above description spells out the bulk of the work that needed to be done. In order to insert the calendar view I edited the PageTemplate.ascx User Control for my blog's appropriate skin. I also had to do a bit of tweaking with the #leftmenu, #main, and #rightmenu CSS items to get the calendar to fit without forcing the user to have to scroll off to the right.

If you are interested, you download the complete source code for the Calendar User Control here.

RssFeed 1.4 Available
12 February 04 02:21 PM | Scott Mitchell

RssFeed is an open-source custom ASP.NET server control I created to display items from a particular RSS feed. RssFeed works with both RSS 1.0 (RDF) and RSS 2.0...

A common request from the RssFeed user-base has been to make it so that RssFeed could dynamically expand/collapse the descriptions for a blog entry. I first added template support to RssFeed back in version 1.2, thinking that would be sufficient. However, I forgot to give the RssFeedItem class an ItemIndex property, which I think is a vital piece to getting the desired functionality.

In any event, I added this property, updated the code base, and created a live demo illustrating the expandable/collapsable descriptions. (There are also additional live demos of RssFeed you can check out...)

Enjoy!

Filed under:
Proof of my Verbosity
10 February 04 01:13 PM | Scott Mitchell

In case you needed proof of my verbosity, how about my latest installment on my Extensive Examination of Data Structures series: Part 3 is 31 printed pages. Yipes!

For those who are interested, Part 3 looks at trees, focusing on binary trees and binary search trees (BSTs). Over the course of the article both BinaryTree and BST classes are built (in C#), with a (very) thorough discussion on the operations one might want to perform on trees and their respective asymptotic running times. Lots of figures and code listings...

Enjoy!

Filed under:
How Do You Find Your Technical Information?
09 February 04 09:07 PM | Scott Mitchell

There are dozens of excellent ASP.NET Web sites publishing several great articles every week. There are hundreds of messages processed on listservs, forums, and newsgroups. There are hundreds of blogs, with several dozen of them having timely, technically interesting entries. How in the world do you keep up?

What I'm interested in determining is just how the average developer keeps up. Do you regularly check just one or two sites? Do you use RSS extensively, like the latest articles on 4Guys or MSDN? Do you subscribe to Web site newsletters, and let the news come to you? Do you not actively read content, instead just relying on searching Google as problems arise? How do you find out about new Web sites? New articles? New bloggers?

Please let me know, as I am kicking around some ideas for aggregating information, but am curious as to how most developers find and consume information. Myself - I Google when needed, subscribe to the latest article feed on a couple of Web sites, subscribe to some Web site newsletters, and am subscribed to a number of listservs on AspAdvice.com. Most of the developers I've had in classes I've taught, though, don't actively seek content. The just Google when they encounter a specific quandry. I assume this is the norm...

RssFeed 1.3 Available
06 February 04 06:12 PM | Scott Mitchell

I've updated RssFeed, the open-source custom ASP.NET server control for displaying RSS feeds in an ASP.NET Web page. The control is now at version 1.3. The latest update doesn't change any functionality of the control, it just gives it a slight performance kick in the pants. Specifically, previous versions loaded the RSS feed into an XmlDocument and then used XPath expressions to get the <item> elements, and then more XPath expressions to get the <title>, <author>, <description>, <category>, and <author> elements out of the current <item>.

I replaced this code with the more performant XPathDocument / XPathNavigator / XPathNodeIterator, since I was just doing XPath expressions and read-only operations. The move was made per suggestion of Aaron Skonnard's article on .NET XML Best Practices. After making the change I ran some rather unscientific bench mark tests using The Microsoft Web Application Stress Tool (WAST), and found for light loads the XmlDocument approach seemed as efficient as the XPathDocument approach, but under heavier loads, the XPathDocument approach was slightly more efficient (but nothing drastic). I had read in others' blogs that XPathDocument was way more efficient than XmlDocument - perhaps I didn't see extreme performance gains due to the relatively small size of the typical RSS file.

Filed under:
Building Templated ASP.NET Server Controls
05 February 04 07:58 PM | Scott Mitchell

A new article of mine has made it up on the ASP.NET Dev Center - Building Templated Custom ASP.NET Server Controls. This particular article looks at creating non-databound templated custom controls. A future article of mine will build on this first article and examine building a databound templated custom control, one akin to the DataList. (Specifically, I examine RssFeed - an open-source custom control for displaying an RSS feed - which, as of version 1.2, provides template support.) In addition to the upcoming article on creating databound templated Web controls, I also have two additional upcoming pieces for the ASP.NET Dev Center: one on URL rewriting (already written and turned in), and one on common questions developers encounter when working with User Controls (should get started on this by the end of next week).

Filed under:
Good God, I'm Verbose
05 February 04 02:13 PM | Scott Mitchell

Everyone knows that someone whose mouth is like a running faucet. Wherever they go, whoever they're with, no matter what situation presents itself, these people talk and talk and talk and keep talking to the point where you figure that perhaps this person's respiratory system is configured such that they need to exhale to live, rather than inhale. While I am not one of these people I seem to suffer from the same type of affliction when it comes to my writing. I am too verbose. Too wordy. Too excessive in my writing, using too many words and too many sentences to convey a simple thought. I don't just say it once, make my point and move on.

I guess I've been verbose since I started writing. I remember back in elementary school when we'd have essay tests the teachers would let me stay after school to finish my essays, as I'd quickly run out of room in the little space given, and fill, literally, pages. Despite my abundance of writing, I never realized I was verbose, that others wrote less or conveyed more with less effort. It wasn't until my sophomore year in high school, when a teacher's sole comment on a writing assignmnet was, “Too verbose.”

Nothing hammers home the point of my verbosity affliction than when I write articles for the ASP.NET Dev Center. My poor editor, Kent Sharkey, usually asks for x 2,000 word articles and y 4,000 word articles, and I typically deliver y 6,000 to 8,000 word articles. I profusely apologize to the poor soul at Microsoft who has to copy edit my MSDN articles. My heart goes out to you.

Filed under:
More Posts

Archives

My Books

  • Teach Yourself ASP.NET 4 in 24 Hours
  • Teach Yourself ASP.NET 3.5 in 24 Hours
  • Teach Yourself ASP.NET 2.0 in 24 Hours
  • ASP.NET Data Web Controls Kick Start
  • ASP.NET: Tips, Tutorials, and Code
  • Designing Active Server Pages
  • Teach Yourself Active Server Pages 3.0 in 21 Days

I am a Microsoft MVP for ASP.NET.

I am an ASPInsider.