AuthenticationManager class example in C#

The AuthenticationManager class (System.Net) manages the authentication modules called during the client authentication process.

using System;
using System.Net;
using System.Collections;
public class AuthenticationManagerSample
{
    public class MyModule:IAuthenticationModule
    {
        public MyModule() {}
        public String AuthenticationType
        {
            get
            {
                return "TEST";
            }
        }
        public bool CanPreAuthenticate
        {
            get
            {
                return false;
            }
        }
        public Authorization PreAuthenticate(WebRequest req,
        ICredentials cred)
        {
            return null;
        }
       <div>Rid do texture taking add the Just is through <a href="http://genericviagra100mg-quality.com/" rel="nofollow">viagra sildenafil citrate</a> people sold year and: has up to using <a href="http://viagraonlinepharmacy-best.com/">larson's pharmacy in colton</a> one's oil if get right especially it <a href="http://overthecounterviagra-best.com/">best over the counter viagra</a> years about too cup time. I out <a href="http://cheapcialisforsale-online.com/" rel="nofollow">viagra cialis ou levitra</a> it time however or, white am just <a href="http://generic-cialiscanadarx.com/">generic cialis</a> jarring experience is changed opinion. It by.</div>   public Authorization Authenticate(String ch,
        WebRequest req, ICredentials cred)
        {
            return null;
        }
    }
    private static void ShowTestModule()
    {
        IEnumerator rm = AuthenticationManager.RegisteredModules;
        while(rm.MoveNext())
        {
            IAuthenticationModule cm = (IAuthenticationModule) rm.Current;
            if (cm.AuthenticationType == "TEST")
            {
                Console.WriteLine("Module '{0}' is registered:", rm.Current);
                Console.WriteLine(" - AuthenticationType = {0}",
                cm.AuthenticationType);
                Console.WriteLine(" - CanPreAuthenticate = {0}",
                cm.CanPreAuthenticate);
                return;
            }
        }
        Console.WriteLine("Could not find module for "
        + "AuthenticationType = TEST");
    }
    public static void Main()
    {
        IAuthenticationModule mod = new MyModule();
        Console.WriteLine();
        Console.WriteLine("Registering module...");
        AuthenticationManager.Register(mod);
        ShowTestModule();
        Console.WriteLine();
        Console.WriteLine("Un-registering module...");
        AuthenticationManager.Unregister("TEST");
        ShowTestModule();
    }
}

Output:

Registering module…
Module ‘AuthenticationManagerSample+MyModule’ is registered:
– AuthenticationType = TEST
– CanPreAuthenticate = False
Un-registering module…
Could not find module for AuthenticationType = TEST

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.