Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何与asp.net基于表单的身份验证集成_C#_Asp.net_Asp.net Mvc_Authentication_Nancy - Fatal编程技术网

C# 如何与asp.net基于表单的身份验证集成

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

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

现在我们有了一个nancy登录屏幕,我们还需要使用它进行asp.net表单身份验证。是否有人可以指导我们如何在代码中使用基于asp.net表单的身份验证对用户进行身份验证。 我们计划在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 
}
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,我们可以寻找其他可用的单点登录选项