Byr*_*ahl 20 c# authentication nancy
我开始为Nancy编写一个LoginModule,但我想到可能需要以不同的方式执行身份验证.在南希有一种可以接受的认证方式吗?我现在正在计划两个项目:web和json服务.我需要两个身份验证.
Chr*_*dal 23
正如史蒂文写道,南希支持基本和形式认证.看看这两个演示应用程序,看看如何做每个:https://github.com/NancyFx/Nancy/tree/master/samples/Nancy.Demo.Authentication.Forms和https://github.com/NancyFx/南希/树/主/样品/ Nancy.Demo.Authentication.Basic
从这些演示中的第二个是这个模块需要auth:
namespace Nancy.Demo.Authentication.Forms
{
using Nancy;
using Nancy.Demo.Authentication.Forms.Models;
using Nancy.Security;
public class SecureModule : NancyModule
{
public SecureModule() : base("/secure")
{
this.RequiresAuthentication();
Get["/"] = x => {
var model = new UserModel(Context.CurrentUser.UserName);
return View["secure.cshtml", model];
};
}
}
}
Run Code Online (Sandbox Code Playgroud)
以及在请求管道中设置表单身份验证的引导程序代码段:
protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines, NancyContext context)
{
// At request startup we modify the request pipelines to
// include forms authentication - passing in our now request
// scoped user name mapper.
//
// The pipelines passed in here are specific to this request,
// so we can add/remove/update items in them as we please.
var formsAuthConfiguration =
new FormsAuthenticationConfiguration()
{
RedirectUrl = "~/login",
UserMapper = requestContainer.Resolve<IUserMapper>(),
};
FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13806 次 |
| 最近记录: |