现在的位置: 首页 > 综合 > 正文

AjaxPro

2013年03月17日 ⁄ 综合 ⁄ 共 2008字 ⁄ 字号 评论关闭

 namespace SHI

{

 public partial class Logion : System.Web.UI.Page
    {
        UserInfoBeanDao Uib = new UserInfoBeanDao();
        protected void Page_Load(object sender, EventArgs e)
        {

            //注册ajax
            if (!Page.IsPostBack)
            {
                //SetImgUrl();
                AjaxPro.Utility.RegisterTypeForAjax(typeof(Logion));
            }

        }

        //判断用户名密码是否正确
       [AjaxPro.AjaxMethod]
        public int isRight(string userName, string userPwd)
        {
            int count = 0;
            UserInfoBean u = new UserInfoBean();
            u.Userid = userName;
            u.Pwd = userPwd;
            try
            {
                count =Uib.ValuateUser(u);

            }
            catch (Exception)
            {

                throw;
            }
            return count;
        }

             //写入Session值
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public void WriteSession(string userID)
        {
            Session["Logion"] = userID;
        }
     
    }

}

简单的利用ajaxpro 实现登录用户名密码的判定

扩展阅读:

AjaxPro 应用简述:

首先ajaxpro 的引入 在网上搜索并下载ajaxpro.dll  ,然后右击应用程序 添加引用选项

第二步:配置web.config  这一步作用是保证客户端向“ajaxpro/*.ashx”的请求(Post 和Get )都被AjaxPro.AjaxHandlerFactory 拦截。

在<configuration><system.web> 后添加代码:

<httpHandlers><add verb="POST ,GET" path ="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro"/></httpHandlers>

注意在后台写的时候一定要添加  [AjaxPro.AjaxMethod]标志 以便在客户端访问

 访问方法:

 

function check() {
            var userName = document.getElementById("TxtName").value;

            var userPwd = document.getElementById("TxtPwd").value;
          
                if (SHI.Logion.isRight(userName + "", userPwd + "").value > 0) {
                     //写入Session

                    SHI.Logion.WriteSession(userName + "");
                    window.location.href = '/LeftMenu.aspx';
                                }
                else {
                    alert("用户名或密码不正确!");
                }

      }

ajax: ajax 是异步javascript 和xml (Asynchronous JavaScript and xml )的英文缩写  其核心理念在于使用XMLHttpRequest 对象发送异步请求

ajax 可以减轻服务器负担,无需刷新页面,减少用户实际等待时间,

xmlHttpRequest 对象扩展阅读

http://www.w3school.com.cn/xmldom/dom_http.asp 

 

 

 

抱歉!评论已关闭.