本随笔主要参考了MSDN

  在开发商业软件时,往往需要给软件实现某种类型的许可,以限制非授权用户的使用。一般情况下,开发者会采取建立并检查特定的授权文件或在注册表中添加表项的方法来实现授权机制。但对于商业控件的开发而言,它所面对的对象是二次开发者而不是最终用户,采用传统的方法进行授权验证会有不少的问题。令人欣喜的是,.NET框架提供了内置的授权方案,利用它能非常方便的实现带授权机制的控件开发,并且开发者可以覆盖它并创建自己的授权验证方案。

一、简单的一个例子

To enable licensing for your component or control

 

LicenseProviderAttribute to the class.

LicenseProviderAttribute 特性。

IsValid in the constructor.

Validate函数。

Dispose on any granted license in the finalizer of the class or before the finalizer is called.

Dispose函数。

 

LicFileLicenseProvider, which enables you to use text license files.

 

using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace TestLicense
{
    // Adds the LicenseProviderAttribute to the control.
    [LicenseProvider(typeof(LicFileLicenseProvider))]
    public class MyControl : Control
    {
        // Creates a new, null license.
        private License license = null;

        public MyControl()
        {
            // Adds Validate to the control's constructor.
            license = LicenseManager.Validate(typeof(MyControl), this);

            // Insert code to perform other instance creation tasks here.
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (license != null)
                {
                    license.Dispose();
                    license = null;
                }
            }
        }

    }  
        
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-24
  • 2022-02-19
  • 2021-09-03
  • 2021-04-21
  • 2021-08-05
  • 2021-10-22
  • 2022-01-30
相关资源
相似解决方案