栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

.NET的Ajax请求数据提交实例

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

.NET的Ajax请求数据提交实例

本文实例讲述了.NET的Ajax请求数据提交实现方法。分享给大家供大家参考。具体如下:
复制代码 代码如下:<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %> 
 
 
    ajax请求 
     
     
     
 
 
     
     
         
            ajax请求 
     
     
     
         
             
         
             
                会员登录没有账号?'>立即注册 
 
             
         
     
 
 

控制器
复制代码 代码如下:using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using System.Text; 
 
namespace bigtree.Controllers 

    using bigtree.Models; 
    using bigtree.Model; 
    using bigtree.lib; 
    using System.Net.Mail; 
    using System.Text.Regularexpressions; 
 
    public class LoginController : Controller 
    { 
        public ActionResult Index() 
        { 
            return View(); 
        } 
        ///

 
        /// 检查登陆 
        ///
 
        ///  
        ///  
        [HttpPost] 
        public ActionResult CheckLoginInfo(FormCollection f) 
        { 
            try 
            { 
                //post:   user , pwd ,remembered 
                string user = f["user"].Trim(); 
                string pwd = f["pwd"].Trim(); 
                string remembered = f["remembered"].Trim(); 
 
                JsonResult res = new JsonResult(); 
                if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pwd)) 
                { 
                    res.Data = new { status = 0 }; 
                } 
                //MD5加密后的密码 
                pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5").ToLower(); 
                //从数据库读取 
                Common.WebUser account = MemberInfoService.GetMemberIdForCheck(user, pwd); 
                if (account == null) 
                { 
                    res.Data = new { status = 0 }; 
                } 
                else 
                { 
                    //{status: 1(success)/0(fail),} 
                    res.Data = new { status = 1 }; 
                    //todo:登陆成功,记录登陆用户信息保存登陆状态 
                    FunSession.SetSession(account); 
 
                    //是否记住登录 
                    if (remembered == "on") 
                    { 
                        Httpcookie cookie = new Httpcookie("LoginInfo", account.Id.ToString()); 
                        //3天有效 
                        cookie.Expires.AddDays(3); 
                        Response.cookies.Add(cookie); 
                    } 
                    else 
                    { 
                        Httpcookie cookie = new Httpcookie(account.Id.ToString(), account.Id.ToString()); 
                        //使失效 
                        cookie.Expires.AddYears(-1); 
                        Response.cookies.Add(cookie); 
                    } 
                } 
                return res; 
            } 
            catch (Exception ex) 
            { 
                throw ex.InnerException; 
            } 
        } 
    } 
}

希望本文所述对大家的.NET程序设计有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/56884.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号