如何在jQuery中使用asp.net验证的用户名密码? [英] How to authenticate username password in Jquery with asp.net?

查看:93
本文介绍了如何在jQuery中使用asp.net验证的用户名密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有jQuery的登录控制魔神使用这种进入asp.net,但以下code,但相混淆,我怎么可以简单地验证用户名和密码。

I have code of Jquery login control loke following using this into asp.net but but confused where and how I can simply authenticate username and password.

的Login.aspx

<head>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Scripts/login.js" type="text/javascript"></script>
</head>

 <div id="loginBox">                
                    <form id="loginForm">
                        <fieldset id="body">
                            <fieldset>
                                <label for="email">Email Address</label>
                                <input type="text" name="email" id="email" />
                            </fieldset>
                            <fieldset>
                                <label for="password">Password</label>
                                <input type="password" name="password" id="password" />
                            </fieldset>
                            <input type="submit" id="login" value="Sign in" />
                            <label for="checkbox"><input type="checkbox" id="checkbox" />Remember me</label>
                        </fieldset>
                        <span><a href="#">Forgot your password?</a></span>
                    </form>
                </div>

Login.js
// Login Form

$(function() {
    var button = $('#loginButton');
    var box = $('#loginBox');
    var form = $('#loginForm');
    button.removeAttr('href');
    button.mouseup(function(login) {
        box.toggle();
        button.toggleClass('active');
    });
    form.mouseup(function() { 
        return false;
    });
    $(this).mouseup(function(login) {
        if(!($(login.target).parent('#loginButton').length > 0)) {
            button.removeClass('active');
            box.hide();
        }
    });
});

现在我怎么可能用我的asp.net身份验证这个jQuery code? 在哪里以及如何编写C#验证code? 给某些主题M在jQuery的新国际展览局 谢谢

Now How could I use my asp.net authentication with this Jquery code ? where and how to write c# authentication code? give some threads also m new bie in jquery thanks

推荐答案

我不知道什么是你想完全做到,但为了执行与asp.net登录,您应该以某种方式发送数据到服务器。你可以这样做在两个方面:它的形式或通过AJAX请求发送。如果你想在窗体中发送,您应该在标签的形式指定动作,如:

I'm not sure what are you trying exactly to do, but in order to perform log on with asp.net you should send your data somehow to the server. You can do it in two ways: send it with form or by AJAX request. If you want to send it within the form, you should specify action in your tag form, e.g.

<form id="loginForm" action="MySite/Logon">
    <!-- fields, labels, etc. -->
</form>

如果你想将它通过jQuery AJAX请求发送时,您可以使用 jQuery.ajax 的方法,这是明确解释的此处,与相应的URL中的网​​址参数。
在服务器端,您的验证可能会是这样的:

If you want to send it via jQuery AJAX request, you can use jQuery.ajax method, which is clearly explained here, with corresponding url in url parameter.
On the server side, your authentication may look like this:

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( // create authentication ticket
    1, // id
    email, // user name
    DateTime.Now, // date of issue
    DateTime.Now.AddMinutes(15), // expiration date
    true, // true if your ticket will be stored in a cookie, that will be kept by browser across the sessions
    userdata, // any text data, that you want to add to ticket (e.g. user roles)
    FormsAuthentication.FormsCookiePath // path associated with your ticket
);
string hashedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
    FormsAuthentication.FormsCookieName, hashedTicket); // adding your ticket to cookie
cookie.Expires = ticket.Expiration;
Response.Cookies.Add(cookie); // sending cookie to client with current response

这些行动后,您的客户端将被验证,直到他注销或饼干/票证过期时间到期认可。
希望这个信息将帮助你。

After these actions, your client will be recognized as authenticated until he logs off or expiration time of cookie/ticket expires.
Hope this info will help you.

这篇关于如何在jQuery中使用asp.net验证的用户名密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆