C# 如何与asp.net基于表单的身份验证集成
我们正在将基于asp.net的应用程序迁移到nancy,因为应用程序非常大,所以我们决定将应用程序混合并逐页迁移到nancy 现在我们有了一个nancy登录屏幕,我们还需要使用它进行asp.net表单身份验证。是否有人可以指导我们如何在代码中使用基于asp.net表单的身份验证对用户进行身份验证。 我们计划在nancy端使用无状态身份验证 非常感谢您的指点 我们有一个登录页面来验证用户凭据 1。登录模块-C# 如何与asp.net基于表单的身份验证集成,c#,asp.net,asp.net-mvc,authentication,nancy,C#,Asp.net,Asp.net Mvc,Authentication,Nancy,我们正在将基于asp.net的应用程序迁移到nancy,因为应用程序非常大,所以我们决定将应用程序混合并逐页迁移到nancy 现在我们有了一个nancy登录屏幕,我们还需要使用它进行asp.net表单身份验证。是否有人可以指导我们如何在代码中使用基于asp.net表单的身份验证对用户进行身份验证。 我们计划在nancy端使用无状态身份验证 非常感谢您的指点 我们有一个登录页面来验证用户凭据 1。登录模块- Post["/login"] = p => { // Ve
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
}
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
}
}
2。Global.asax-
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
}
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。@matjaz,感谢您的链接,但这对我们的情况没有帮助,我们希望在应用程序处于混合模式之前,主要使用基于ASP.NET表单的身份验证,一旦我们完全迁移到nancy,我们可以寻找其他可用的单点登录选项