分享

三层架构模拟mvc

 贾朋亮博客 2014-04-03
前段登录:
//登陆操作
        function loginSys(username,password) {
            $.ajax({
                type: "POST",
                dataType: "json",
                //cache:true,
                url: "Service/EasyUiService.ashx?Method=Login",
                data: { username: username, password: password },
                success: function(json) {
                    if (json.Flag[0].Status == 1) {
                        window.location.href = "Index.aspx";
                    }
                    else {
                        $.messager.alert('错误', '账号或密码错误!', 'error');
                    }
                },
                error: function() {
                    $.messager.alert('错误', '获取账号信息失败...请联系管理员!', 'error');
                }
            });

后台模拟:
 HttpRequest Request;
        HttpResponse Response;
        HttpSessionState Session;
        HttpServerUtility Server;
        HttpCookie Cookie;

        public void ProcessRequest(HttpContext context)
        {
            //不让浏览器缓存
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            context.Response.ContentType = "text/plain";

            Request = context.Request;
            Response = context.Response;
            Session = context.Session;
            Server = context.Server;

            string method = Request["Method"].ToString();
            MethodInfo methodInfo = this.GetType().GetMethod(method);
            methodInfo.Invoke(this, null);
        }



  /// <summary>
        /// 登陆
        /// </summary>
        public void Login()
        {
            string username = Request["username"].ToString();
            string password = Request["password"].ToString();

            int flag = UserAccess.GetInstance().Login(username, password);
            int? roleId = RoleAccess.GetInstance().GetRoleIdByUsername(username);

            Cookie = new HttpCookie("RoleInfo");
            Cookie["roleId"] = roleId.ToString();
            Cookie.Expires = DateTime.Now.AddMonths(1);
            Response.Cookies.Add(Cookie);

            JsonConvert<object> jc = new JsonConvert<object>();
            Response.Write(jc.ToStatus(flag));
        }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多