扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage
专注于为中小企业提供成都网站设计、成都网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业尚义免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千多家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
控制器
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 };
//codego.net/#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;
}
}
}
}
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流