Licensing in .NET
By Myk Willis, October 01, 2003
The Microsoft.NET licensing model works well for the kind of redistributable components that developers buy and redistribute as a part of an application. In this article, we'll enable licensing support for a simple redistributable component, and see how Visual Studio .NET automates much of the licensing process for components.
Licensing in .NET
Listing 7 A component that displays a visible message when used in evaluation mode
using System;
using System.ComponentModel;
using System.Windows.Forms;
[LicenseProvider(typeof(EvaluationLicenseProvider))]
public class TryAndBuyComponent : UserControl
{
private Label evaluationLabel;
private void InitializeComponent()
{
this.evaluationLabel = new System.Windows.Forms.Label();
this.evaluationLabel.Text = "Evaluation Mode";
this.Controls.Add( this.evaluationLabel );
}
public TryAndBuyComponent()
{
CustomLicense license;
InitializeComponent();
license = (CustomLicense) LicenseManager.Validate(
typeof(TryAndBuyComponent), this );
if ( license.IsEvaluation ) evaluationLabel.Visible = true;
else evaluationLabel.Visible = false;
license.Dispose();
}
}