NancyFx 2.0のオープンソースフレームワークの使用-Basic
これはNancyFxオープンソースフレームワークのBasic認証です.勉強してください.
まずもちろん空のWebを新規作成し、BasicDemo
引き続きプロジェクトにNugetパッケージを追加し、インストールしたNugetパッケージが最新のプリリリース版であることを覚えています.
その後、プロジェクトにModelsフォルダとModuleフォルダを追加し、ModelsフォルダにUserValidatorクラスを追加します.
public ClaimsPrincipal Validate(string username,string password)
{ if (username=="Lexan"&&password=="password")
{ return new ClaimsPrincipal(new GenericIdentity(username));
} // =>
return null;
}
引き続きModuleファイルにMainModuleクラスを追加
public MainModule()
{
Get("/",Lexan=>"アドレスバー /secureアクセスSecureページ");
}
引き続きModuleフォルダにSecureModuleクラスを追加
public SecureModule() : base("/secure")
{
this.RequiresAuthentication();
Get("/", args => "Hello " + this.Context.CurrentUser.Identity.Name);
}
ルートディレクトリにBasicBootstrapperクラスを追加し、プロジェクトの初期化に使用します.
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{ base.ApplicationStartup(container, pipelines);
pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(container.Resolve(),"Lexan"));
}
作成したアイテムを実行して、ログインアカウントとパスワードをUserValidatorクラスに書きました.