从Windows窗体登录到ASP.NET Web窗体

时间:2019-07-16 03:04:11

标签: c# asp.net forms-authentication winforms-to-web

我有一个网站,我在该网站上注册用户并为这些用户设置一些会话值。该网站还启动了Windows窗体应用程序,其中我将登录凭据传递给Windows窗体。

然后,winform应用程序使用“ HttpWebRequest”对象回调网站/服务器代码,并传递用户凭据等参数。

在我网站的页面加载功能上,我有以下代码:

if (User.Identity.IsAuthenticated)
        {
            Session["Name"] = "Sidd";
            Session["Country"] = "India";
        }
        else
        {               
            //Response.Redirect("~/About.aspx");
            string email = Request.Form["Email"];
            string password = Request.Form["Password"];

            if(email != null && password != null)
            {
                var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
                var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();
                //var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
                var result = signinManager.PasswordSignIn(email, password, isPersistent: false, shouldLockout: false);
                if (result == SignInStatus.Success)
                {
                    //Page.Response.Redirect(Page.Request.Url.ToString(), true);
                    IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                }
            }                            
        }

public static void RedirectToReturnUrl(string returnUrl, HttpResponse response)
    {
        if (!String.IsNullOrEmpty(returnUrl) && IsLocalUrl(returnUrl))
        {
            response.Redirect(returnUrl);
        }
        else
        {
            response.Redirect("~/");
        }
    }

因此,上面的代码对我来说基本上重定向到根网站default.aspx

即使SigInManager结果返回成功登录状态,上面的代码仍然为我提供User.Identity.IsAuthenticated值为false的重定向。

所以我有两个问题: 1.)如何在跨域方案中验证/认证用户 2.)从Windows窗体返回网站时,如何获取用户已登录用户的会话值

任何链接,指导或建议都很棒。

在此先感谢!!! ..

0 个答案:

没有答案
相关问题