【发布时间】:2018-03-10 17:12:58
【问题描述】:
我们正在将基于 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
}
}
【问题讨论】:
-
@matjaz,感谢您的链接,但在我们的情况下它没有帮助,我们希望主要使用基于 Asp.net 表单的身份验证,直到我们的应用程序处于混合状态模式,一旦我们完全迁移到 nancy,我们就可以寻找其他可用的单点登录选项
标签: c# asp.net asp.net-mvc authentication nancy