BN089-BS开发框架MVC4版/source20131023/Zephyr.Net/Zephyr.Core/Core/FormsAuth.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/*************************************************************************
* 文件名称 :FormsAuth.cs
* 描述说明 :窗体登陆验证
*
* 创建信息 : create by liuhuisheng.xm@gmail.com on 2012-11-10
* 修订信息 : modify by (person) on (date) for (reason)
*
* 版权信息 : Copyright (c) 2013 厦门纵云信息科技有限公司 www.zoewin.com
**************************************************************************/
using System;
using System.Web;
using System.Web.Security;
using Newtonsoft.Json;
namespace Zephyr.Core
{
public static class FormsAuth
{
public static void SignIn(string loginName, object userData, int expireMin)
{
var data = JsonConvert.SerializeObject(userData);
//创建一个FormsAuthenticationTicket,它包含登录名以及额外的用户数据。
var ticket = new FormsAuthenticationTicket(2,
loginName, DateTime.Now, DateTime.Now.AddDays(1), true, data);
//加密Ticket,变成一个加密的字符串。
var cookieValue = FormsAuthentication.Encrypt(ticket);
//根据加密结果创建登录Cookie
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieValue)
{
HttpOnly = true,
Secure = FormsAuthentication.RequireSSL,
Domain = FormsAuthentication.CookieDomain,
Path = FormsAuthentication.FormsCookiePath
};
if (expireMin > 0)
cookie.Expires = DateTime.Now.AddMinutes(expireMin);
var context = HttpContext.Current;
if (context == null)
throw new InvalidOperationException();
//写登录Cookie
context.Response.Cookies.Remove(cookie.Name);
context.Response.Cookies.Add(cookie);
}
public static void SingOut()
{
FormsAuthentication.SignOut();
}
public static LoginerBase GetUserData()
{
return GetUserData<LoginerBase>();
}
后面还有 17 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。