|
Who Are We?Fluent Consulting is a software development and consulting firm that specializes in enterprise application integration, web applications, and software product development. We are a dedicated team focused on providing the highest level of quality and value for our clients. Please feel free to visit our corporate site or get in touch! |
Category Archive: .NET
Bi-directional Data Binding for ASP.NET 1.0/1.1
There's only so much casting, converting, parsing that one can take trying to push and pull data from custom objects into form controls. Although, ASP.NET 2.0 has improved the situation, there's another simple model to package up some of this common code into a reusable component. Continue reading "Bi-directional Data Binding for ASP.NET 1.0/1.1"IIS Nested Virtual Directory Problems
Microsoft Internet Information Server (IIS) 5.1 has an undocumented bug we recently came across. The bug involves nested virtual directories in IIS. We encountered the bug on a development machine running Windows XP Professional (with IIS 5.1), but it may also exist on servers running IIS 6.0. The fix is easy, once you know what is going on.
The quick fix is to not include a period (.) in the name of a nested virtual directory. For some reason a period prevents nested virtual directories from loading properly. With a period in the name, the nested virtual directory is instead treated as just a directory by IIS. Your files are available, but they tie back to the parent bin rather than the nested bin.
Continue reading "IIS Nested Virtual Directory Problems"Creating Templated Emails
Often we need to generate email responses from our ASP.NET applications. Users forget their passwords, need email confirmations, or we'd just like to send them a friendly thank you for signing up.
Now you could create that email message with a nice series of string concatenations, or some fancy xml/xslt transformation. But who needs that when there is an easier way using what's available from our aspx parser?
First thing to create is a typical user control. This will be your template.
ForgotPasswordEmail.ascx<%@ Control Language="c#" AutoEventWireup="false" Codebehind="ForgotPasswordEmail.ascx.cs" Inherits="EmailTemplateExample.ForgotPasswordEmail" %> Here is your password reminder. ----------------------------------- YOUR ACCOUNT INFORMATION: Login: <%= Username %> Password: <%= Password %> ----------------------------------- TO CHANGE YOUR ACCOUNT INFORMATION: You can change your account information by logging in and selecting 'Account Information'. This is an automated message; please do not reply to this email.ForgotPasswordEmail.ascx.cs
namespace EmailTemplateExample { public abstract class ForgotPasswordEmail : System.Web.UI.UserControl { public string Username; public string Password; } }Once you have created the template, using it only takes a few lines of code.
using System; using System.IO; using System.Web.UI; using System.Web.Mail; ... //Load the user control ForgotPasswordEmail emailTemplate = (ForgotPasswordEmail)LoadControl("~/ForgotPasswordEmail.ascx"); emailTemplate.Username = "jroberts"; emailTemplate.Password = "a7e945"; //Render the user control to a string StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter); emailTemplate.RenderControl(htmlWriter); string body = stringWriter.ToString(); //Send the email SmtpMail.SmtpServer = "localhost"; SmtpMail.Send("system@localhost","jroberts@localhost", "Password Reminder", body);Your template could have more complex behavior, having the full power of the ASP.NET user control model. Additionally, using html in your user control to create html emails only requires properly setting the format of the MailMessage.
//Prepare HTML email MailMessage mailMessage = new MailMessage(); mailMessage.From = "system@localhost"; mailMessage.Subject = "Password Reminder"; mailMessage.BodyFormat = MailFormat.Html; mailMessage.UrlContentBase = "http://localhost/"; //Send the email SmtpMail.SmtpServer = "localhost"; SmtpMail.Send(mailMessage);
Fluent.ControlFocus Component Now Available
We have released a new aspect oriented .NET component which may be of interest to developers. It is a very simple non-visual web control which will automatically set focus to a given WebControl after the page has completed loading. This may be useful in situations such as page validation, for example, if you want the cursor to be positioned in a given field which needs correction after a validation failure on postback. The control has one simple attribute, and is used as follows:
<%@ Register TagPrefix="fluent" Namespace="Fluent.ControlFocus" Assembly="Fluent.ControlFocus" %> ... <asp:TextBox runat="server" ID="FirstTextBox" /><br/> <%-- the control below, SecondTextBox, will be focused on page load --%> <asp:TextBox runat="server" ID="SecondTextBox" /> <fluent:ControlFocus runat="server" Control="SecondTextBox" />
Please visit the Fluent Consulting aspect oriented components section for more information or to download this free component!
CLR Proc Container
.NET Framework Bootstrapper
Visual Studio .NET Framework Bootstrapper Plug-in: Home
Aspect Oriented Components: An Introduction
I'd like to describe a component development strategy that we've been using at Fluent Consulting for some time that has proven very useful. It has become common knowledge that software functionality which is implemented in a similar manner over and over again is a good candidate for being re-written and deployed as a component. In the .NET framework this would typically be done by wrapping your reusable functionality into a custom server control and deploying it as a standalone DLL, which can be dropped into the /bin folder of any application.
In many situations these types of components are very valuable, and we have built up a library of such components that we often use when developing applications. There are times, however, when the code we would like to be able to reuse is not standalone functionality, but rather needs to be interwoven with existing code. In these cases we have adopted a modified component development strategy, based on aspect-oriented software development. For more information about aspects you can review a list of papers published by XEROX PARC (where AOP was invented), a list of aspect development tools, or an article about implementing aspects in C#. I'll describe our methodology with an example.
The .NET framework offers a number of rich web controls which can be bound to data sources and populated at runtime. The DataGrid is the best known of these. Suppose you wanted to make a few changes to how the DataGrid control worked; here's an example of an enhancement. If you bind a DataGrid to a data source which is empty at runtime, when the control renders you will see the header and footer but no contents of the DataGrid. A better behavior would be for the DataGrid to not display the header and footer, but rather display to the user a friendly message saying "No results were returned from your search." or something to similar effect.
The traditional strategy for implementing this feature as a component in .NET would be to create a custom server control, which inherits from the DataGrid control, and adds the required functionality to handle empty data sources. There are a number of considerations which make this approach less than ideal however:
- Because the custom control inherits from the DataGrid control, if you'd like similar behavior for similar data-bound controls such as RadioButtonLists or Repeaters, you would have to create new custom controls for each one, subclassing its respective parent class.
- If you want to incorporate this new functionality into existing code, you would have to change all of your existing DataGrids to implement your new control class.
- Using a custom server control tag in your .aspx page instead of the built-in ASP.NET DataGrid control tag, you will lose the nice Visual Studio .NET tag auto-completion features. These IDE completion features can be very useful on controls as complex as the DataGrid, which have many public properties and subtemplates.
A better solution would be to implement this behavior as an Aspect-Oriented Component. With this methodology, our component does not reimplement any DataGrid features directly, but rather hooks in to an existing DataGrid control at runtime and modifies its properties as needed. The original DataGrid control tag remains as is. Here's a code-snippet of the source for our control:
using System; using System.Web.UI.WebControls; using System.Web; using System.Web.UI; namespace Fluent.EmptyRepeaterPanel { /// <summary> /// Fluent.EmptyRepeaterPanel is an aspect oriented component which checks a data source /// bound to a repeater at runtime. If the data source is empty, the repeater is hidden /// and the contents of the panel are shown in its place. /// </summary> public class EmptyRepeaterPanel : Panel, INamingContainer { private string control; public EmptyRepeaterPanel() { } protected override void AddParsedSubObject(object obj) { this.Controls.Add((Control)obj); } protected override void OnPreRender(System.EventArgs e) { base.OnPreRender(e); string controlName = control.Trim(); try { Control c = (Control) Page.FindControl(controlName); if (c is DataGrid) { DataGrid dg = (DataGrid) Page.FindControl(controlName); if (dg.Items.Count == 0) { dg.Visible = false; } else { this.Controls.Clear(); } } else if (c is ListControl) { ListControl lc = (ListControl) Page.FindControl(controlName); if (lc.Items.Count == 0) { lc.Visible = false; } else { this.Controls.Clear(); } } else if (c is Repeater) { Repeater r = (Repeater) Page.FindControl(controlName); if (r.Items.Count == 0) { r.Visible = false; } else { this.Controls.Clear(); } } else { throw new ApplicationException(@" Control not a valid type. Must be a ListControl, DataGrid, or Repeater, or a type inherited from one of these."); } } catch (System.NullReferenceException nre) { throw new ApplicationException(@" EmptyRepeaterPanel unable to find a control named " + controlName + ".", nre); } } /// <summary> /// ID of the Repeater WebControl to hide if it's data source is empty /// </summary> public string Control { get { return control; } set { control = value; } } } }
This code can be compiled down into a DLL and referenced from any application we need to use it in. To make use of it, first we need to register it in our page like this:
<%@ Register TagPrefix="fluent" Namespace="Fluent.Format" Assembly="Format" %>
In this case our DataGrid is implemented as it normally would, but the .aspx page has an additional tag which modifies the behavior of the DataGrid.
<fluent:EmptyRepeaterPanel Runat="server" Control="TestGrid"> <asp:Label Runat="server" Font-Bold="True" ForeColor="red">Sorry, search returned 0 results.</asp:Label> </fluent:EmptyRepeaterPanel> <asp:DataGrid Runat="server" ID="TestGrid" AutoGenerateColumns="False" ShowFooter="True"> <Columns> <asp:BoundColumn DataField="SSN" HeaderText="SSN" /> <asp:BoundColumn DataField="FNAME" HeaderText="FNAME" /> <asp:BoundColumn DataField="LNAME" HeaderText="LNAME" /> </Columns> </asp:DataGrid>
With this approach we've made it quite easy to modify the behavior of existing native .NET web controls. Aspect Oriented Components are a clean and simple way to add powerful new functionality to your code. In the coming weeks, we will be describing our approach in further detail and discussing promising potential uses.
XML Data-binding
XML.com: XML Data-Binding: Comparing Castor to .NET [Jul. 24, 2002]
Why Java is Better than .NET
101 Reasons Why Java is Better than .NET
This post is bound to be flame-bait because the Java vs. .NET debate often turns into a holy war of sorts. Nevertheless, debating the pros and cons of the two leading application development frameworks will only help ensure that the future releases of each are both more powerful and easier to use, which will benefit everyone. It's interesting to note that many of the advantages of Java present in this list have to do with the huge number of open source projects supporting Java debelopment, many of which are in the process of being ported to the .NET framework since they have proven so useful. Good examples of this phenomenon include NAnt and NUnit. Food for thought.
VS.NET and NAnt
Gordon Weakliem has a post with good resources regarding using NAnt alongside Visual Studio .NET - check it out here.
ASP.NET unit testing
NUnitAsp - ASP.NET unit testing
NUnitAsp is a tool for automatically testing ASP.NET web pages. It's an extension to NUnit, a tool for test-driven development in .NET.
Microsoft Baseline Security Analyzer
Microsoft Baseline Security Analyzer
As part of its Security push, Microsoft has developed the Microsoft Baseline Security Analyzer (MBSA) application that helps identify common security misconfigurations. Version 1.1 is the second release of MBSA and includes a graphical and command line interface that can perform local or remote scans of Windows and IIS systems.
Hosting ASP.NET for free
Hosting ASP.NET - Running Cassini with Apache
ASP.NET client-side hosting
Cutting Edge: ASP. NET Client-side Hosting with Cassini
Suppose that one of your clients needs to distribute some online content using a CD%u2014an encyclopedia, yellow pages, or a collection of documents, for example. The client needs a viewer application to be included with the CD and a flexible software architecture to deliver the contents. Furthermore, the client would prefer that the CD didn't inconvenience the user with special system requirements other than a minimum processor and a recent version of Windows®. This means that the final application should not rely on Microsoft® Internet Information Services (IIS) or the Personal Web Server included in home versions of Windows. It should run offline in a pure, serverless environment.
Web platform cross-deployment
Everybody should be excited at the multiplying efforts to support interoperability between Java and .NET. There's been a few interesting development recently. Today I stumbled upon the IK.VM.NET Weblog, which documents the on-going development of a Java Virtual Machine for .NET.
What to make of these projects? The most basic effect should be to force the J2EE and .NET camps into more direct and finer-grained competition. If it really becomes feasible to deploy the same codebase onto both of the major categories of application servers, we'll be able to choose the best platform for the job on every single project, rather than being locked into previous platform commitments. This gives us developers more control over our work and also intensified competition between the Microsoft and J2EE camps, which should improve the quality, performance, and ease-of-use of both.
The first of these projects I was aware of is Mono and it remains the most promising, despite detractors to feel (perhaps rightly?) that Microsoft will legally be able to shut the project down at it's will. There was a lively Slashdot debate last week on this topic.
Miguel from Ximian writes:



