繁体   English   中英

如何将 nancy 与基于 ASP.NET 表单的身份验证集成

[英]How to integrate nancy with asp.net Form based authentication

我们正在将基于 asp.net 的应用程序迁移到 nancy,因为应用程序非常大,所以我们决定使应用程序混合并逐页迁移到 nancy。

现在我们有一个 nancy 登录屏幕,我们还需要使用它进行 asp.net 表单身份验证。 有人可以指导我们如何在 nancy 代码中使用基于 asp.net 表单的身份验证对用户进行身份验证。 我们计划在 nancy 端使用无状态身份验证。

任何指针都受到高度赞赏。

我们有一个 nancy 登录页面来验证用户凭据

1.登录模块-

 Post["/login"] = p =>
            {
// Verify user crdentials first
// Success, create non-persistent authentication cookie.
                    System.Web.Security.FormsAuthentication.SetAuthCookie(credentials.tbUser, false);
                    var cookie = System.Web.Security.FormsAuthentication.GetAuthCookie(credentials.tbUser, false);
                    cookie.Expires = DateTime.UtcNow.AddHours(5);
                    HttpContext.Current.Response.Cookies.Set(cookie);
return Response.AsRedirect("~/listRequest.aspx"); // used Nancy's redirect model to navigate to another page 
}

2. Global.asax -

void Application_PostAuthenticateRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            FormsIdentity fIdent = application.Context.User.Identity as FormsIdentity;
            if (fIdent != null) **// It always returns null even after ".ASPXAUTH" cookie is successfully created**
            {
                FormsAuthenticationTicket ticket = fIdent.Ticket;  // to see if the ticket exists
            }
        }

我尚未测试但似乎可能的想法之一是使用 Nancy.Authentication.Forms 的 LoginWithoutRedirect 方法。

您的应用程序将同时管理 ASP.NET 的身份验证 cookie 和 Nancy Forms 的身份验证 cookie。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM