ASP.NET 2.0 JQuery AJAX 登錄 (ASP.NET 2.0 JQuery AJAX Login)


問題描述

ASP.NET 2.0 JQuery AJAX 登錄 (ASP.NET 2.0 JQuery AJAX Login)

I'm trying to figure out how to implement an AJAX login for a ASP.NET 2.0 site with Jquery. I already have a implemented other simple Jquery AJAX application on the site, but I'm unsure how to convert over the standard login control to POST via AJAX.  Should I expose the login.aspx page methods?  Any help would be great.


參考解法

方法 1:

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
  }
});

方法 2:

With this solution there is a big security problem that username and password will be send in plain-text format. so you should use SSL or hash these data in some way.  take a look here

(by GreenEggsJose BasilioMahdi)

參考文件

  1. ASP.NET 2.0 JQuery AJAX Login (CC BY-SA 3.0/4.0)

#login #ASP.NET #controls #jquery #ajax






相關問題

只允許 oracle db 登錄到特定的應用程序? (Allowing oracle db login only to specific application?)

使用 FB.login 的註冊流程 (Registration flow using FB.login)

asp.net c# sistem login (asp.net c# login system)

Rails 設計登錄不工作 (Rails devise sign in not working)

我在 cakephp 2.4 中遇到了登錄頁面 (I'm getting stuck with login page in cakephp 2.4)

如何刪除特定用戶的會話登錄 (How to remove session login for specific user)

有沒有標準的asp.net認證授權登錄系統? (Is there a standard asp.net authentication authorization login system?)

所有這些網絡平台如何實現不需要用戶反复登錄的長時間登錄會話? (How do all these web platforms achieve a long-time login session that does not require the user to login over and over again?)

Util-Linux 登錄不使用影子密碼 (Util-Linux Login not working with shadow password)

Android Webview Facebook 登錄 (Android Webview Facebook Login)

重置 Bookstack 憑據 (Reset Bookstack Credentials)

輸入正確的詳細信息且未顯示錯誤後,登錄頁面未重定向到 index.php (Login in page not redirecting to index.php after entering correct details with no error displayed)







留言討論