weixin_33743703 2009-05-18 16:47 采纳率: 0%
浏览 39

如何使用Jquery为ASP.NET 2.0站点实现AJAX登录?

我想搞清楚如何使用Jquery为ASP.NET 2.0站点实现AJAX登录。

我已经在站点上实现了另一个简单的Jquery AJAX应用程序,但是我不确定如何通过AJAX将标准登录控件转换为POST。我应该公开login.aspx页面方法吗?

任何帮助都将不胜感激!

  • 写回答

2条回答 默认 最新

  • weixin_33737134 2009-05-18 22:00
    关注

    Here are some ideas on how this can be implemented. This is not full code, but it should be enough to get you started on the right track.

    You need to create your own login form fields for username/password.

    Create an ASMX or WCF WebService for authentication with a method similar to this:

    [WebMethod]
    public string AuthenticateUser(string username, string password)
    {
        string result = "Invalid Username or Password";
        if(Membership.ValidateUser(userName, password))
        {
            FormsAuthentication.SetAuthCookie(u.UserName, false);
            result = "successful";
        }
        return result;
    }
    

    Then from your login button's click event you can use jQuery ajax to post the username/password to the webservice:

    $.ajax({
      type: "POST",
      url: "WebService.asmx/AuthenticateUser",
      data: "{username:"+$('#txtUsername').val()+",password:"+$('#txtPassword').val()+"}",
      success: function(result) {
         alert(result);
        //if(result=='successful')
       // redirectUser to the home page
      }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?